Changeset 59 in MondoRescue
- Timestamp:
- Oct 11, 2005, 1:34:31 AM (20 years ago)
- Location:
- trunk/mondo/mondo
- Files:
-
- 66 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/common/X-specific-EXT.h
r30 r59 2 2 3 3 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); 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, 13 long max_val); 14 extern void log_file_end_to_screen(char *filename, char *grep_for_me); 15 extern void log_to_screen(const char *op, ...); 16 extern void popup_and_OK(char *prompt); 17 extern int popup_and_get_string(char *title, char *b, char *output, 18 int maxsize); 19 extern int popup_with_buttons(char *p, char *button1, char *button2); 20 extern void refresh_log_screen(); 21 extern void setup_newt_stuff(); 22 extern void update_evalcall_form_ratio(int num, int denom); 23 extern void update_evalcall_form(int curr); 24 extern void update_progress_form(char *blurb3); 25 extern void update_progress_form_full(char *blurb1, char *blurb2, 26 char *blurb3); 24 27 25 28 … … 27 30 28 31 29 extern t_bkptype which_backup_media_type 30 extern int which_compression_level 32 extern t_bkptype which_backup_media_type(bool); 33 extern int which_compression_level(); 31 34 32 35 33 extern void popup_changelist_from_file(char*source_file); 34 35 36 extern void popup_changelist_from_file(char *source_file); -
trunk/mondo/mondo/common/X-specific.h
r30 r59 7 7 #endif 8 8 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); 43 47 44 48 #if __cplusplus && WITH_X 45 49 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" */ 50 53 #include <qvaluelist.h> 51 54 #include <qwidget.h> … … 54 57 #include <qstring.h> 55 58 #include <qmultilineedit.h> 56 57 59 /** 58 60 * 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 61 62 { 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; 67 69 // union { 68 69 70 71 int len;70 int iParam; 71 QString qsParam, title, text, b1, b2; 72 char *csParam; 73 int len; 72 74 // }; 73 74 Event() : type (None), data (0) {}75 Event (EventType thetype, QWidget *thedata) {76 77 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 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 /** 111 113 * Queue a "show" event for @p data. 112 114 * This is equivalent to a delayed call of @p data->show(). 113 115 * @param data The widget to show when the event is processed. 114 116 */ 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 /** 120 122 * Queue a "hide" event for @p data. 121 123 * This is equivalent to a delayed call of @p data->hide(). 122 124 * @param data The widget to hide when the event is processed. 123 125 */ 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 /** 129 131 * Queue a "setProgress" event for @p data. 130 132 * This is equivalent to a delayed call of <tt>data-\>setProgress(progress)</tt>. … … 132 134 * @param progress The progress amount to set it to. 133 135 */ 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 /** 139 141 * Queue a "setTotalSteps" event for @p data. 140 142 * This is equivalent to a delayed call of <tt>data-\>setTotalSteps(totals)</tt>. … … 142 144 * @param totals The total number of steps to set. 143 145 */ 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 /** 149 151 * Queue a "setText" event for @p data. 150 152 * This is equivalent to a delayed call of <tt>data-\>setText(text)</tt>. … … 152 154 * @param text The text to set it to. 153 155 */ 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 /** 159 161 * Queue an "insertLine" event for @p data. 160 162 * This is equivalent to a delayed call of <tt>data->insertLine(line)</tt>. … … 162 164 * @param line The line to add. 163 165 */ 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 /** 169 171 * Queue an alert box with two buttons to be displayed. 170 172 * The button pushed (the return value of popup_with_buttons()) will be stored … … 174 176 * @param b2 The second button's text. 175 177 */ 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 /** 186 188 * Queue an info box with one OK button to be displayed. 187 189 * @param text The text of the dialog box. 188 190 */ 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 /** 197 199 * Queue a "fatal error" message. 198 200 * @param text The fatal error. 199 201 */ 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 /** 208 210 * Queue a request for some information from the user. 209 211 * If you want to wait until the text is stored, you can set @p g_result_of_last_event … … 215 217 * @param len The size of the buffer allocated for @p out. 216 218 */ 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 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 /** 230 232 * Clear all events stored in the queue without executing them. 231 233 */ 232 233 _events.erase(_events.begin(), _events.end());234 235 236 234 void clear() { 235 _events.erase(_events.begin(), _events.end()); 236 } 237 238 /** 237 239 * Process all events stored in the queue and then clear them. 238 240 */ 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; 300 314 }; 301 302 #endif 315 316 #endif /* __cplusplus */ -
trunk/mondo/mondo/common/crcttt.h
r30 r59 5 5 /** purpose *********************************************************/ 6 6 unsigned int crc16tab[256] = { 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 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 39 39 }; 40 40 41 41 /** purpose **************************************************************/ 42 42 unsigned int crctttab[256] = { 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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 75 75 }; 76 77 78 79 -
trunk/mondo/mondo/common/lib-common-externs.h
r30 r59 7 7 8 8 //extern void log_it(char*); 9 10 11 12 13 -
trunk/mondo/mondo/common/libmondo-archive-EXT.h
r30 r59 2 2 3 3 4 extern int archive_this_fileset (struct s_bkpinfo *bkpinfo, char *filelist, char *fname, int setno); 4 extern int archive_this_fileset(struct s_bkpinfo *bkpinfo, char *filelist, 5 char *fname, int setno); 5 6 extern 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); 7 extern int call_mindi_to_supply_boot_disks(struct s_bkpinfo *bkpinfo); 8 extern bool can_we_fit_these_files_on_media(struct s_bkpinfo *bkpinfo, 9 char *files_to_add, ...); 10 extern int do_that_initial_phase(struct s_bkpinfo *bkpinfo); 11 extern int do_that_final_phase(struct s_bkpinfo *bkpinfo); 12 extern int figure_out_kernel_path_interactively_if_necessary(char *kernel); 13 extern int make_those_slices_phase(struct s_bkpinfo *bkpinfo); 14 extern int make_those_afios_phase(struct s_bkpinfo *bkpinfo); 15 extern int make_slices_and_images(struct s_bkpinfo *bkpinfo, 16 char *biggielist_fname); 17 extern int make_iso_fs(struct s_bkpinfo *bkpinfo, char *destfile); 18 extern int make_afioballs_and_images(struct s_bkpinfo *bkpinfo); 16 19 extern int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...); 17 extern int _move_files_to_cd 20 extern int _move_files_to_cd(struct s_bkpinfo *bkpinfo, char *, ...); 18 21 extern 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); 22 extern int _move_files_to_stream(struct s_bkpinfo *bkpinfo, 23 char *files_to_add, ...); 24 extern int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo 25 *bkpinfo); 26 extern void pause_and_ask_for_cdr(int, bool *); 27 extern 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); 25 33 extern 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 34 extern void wipe_archives(char *d); 35 extern int write_iso_and_go_on(struct s_bkpinfo *bkpinfo, bool last_cd); 36 extern int write_final_iso_if_necessary(struct s_bkpinfo *bkpinfo); 37 extern int call_growisofs(struct s_bkpinfo *bkpinfo, char *destfile); 38 extern int make_afioballs_and_images_SINGLETHREAD(struct s_bkpinfo 39 *bkpinfo); 40 extern int archive_this_fileset_with_star(struct s_bkpinfo *bkpinfo, 41 char *filelist, char *fname, 42 int setno); -
trunk/mondo/mondo/common/libmondo-archive.c
r58 r59 2016 2016 } 2017 2017 for (getline(&bigfile_fname, &n, fin); !feof(fin); 2018 getline(&bigfile_fname, &n, fin), 2019 biggie_file_number++) { 2018 getline(&bigfile_fname, &n, fin), biggie_file_number++) { 2020 2019 use_partimagehack = FALSE; 2021 2020 if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) { -
trunk/mondo/mondo/common/libmondo-archive.h
r58 r59 3 3 */ 4 4 5 int archive_this_fileset (struct s_bkpinfo *bkpinfo, char *filelist, char *fname, int setno); 5 int archive_this_fileset(struct s_bkpinfo *bkpinfo, char *filelist, 6 char *fname, int setno); 6 7 int 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); 8 int call_mindi_to_supply_boot_disks(struct s_bkpinfo *bkpinfo); 9 bool can_we_fit_these_files_on_media(struct s_bkpinfo *bkpinfo, 10 char *files_to_add, ...); 11 int do_that_initial_phase(struct s_bkpinfo *bkpinfo); 12 int do_that_final_phase(struct s_bkpinfo *bkpinfo); 13 int figure_out_kernel_path_interactively_if_necessary(char *kernel); 14 bool get_bit_N_of_array(char *array, int N); 15 int make_those_slices_phase(struct s_bkpinfo *bkpinfo); 16 int make_those_afios_phase(struct s_bkpinfo *bkpinfo); 17 int make_slices_and_images(struct s_bkpinfo *bkpinfo, 18 char *biggielist_fname); 19 int make_iso_fs(struct s_bkpinfo *bkpinfo, char *destfile); 20 int make_afioballs_and_images(struct s_bkpinfo *bkpinfo); 18 21 extern int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...); 19 int _move_files_to_cd 22 int _move_files_to_cd(struct s_bkpinfo *bkpinfo, char *files_to_add, ...); 20 23 extern 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); 24 int _move_files_to_stream(struct s_bkpinfo *bkpinfo, char *files_to_add, 25 ...); 26 int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo 27 *bkpinfo); 28 void pause_and_ask_for_cdr(int, bool *); 29 void set_bit_N_of_array(char *array, int N, bool true_or_false); 30 int 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); 28 34 int verify_data(struct s_bkpinfo *bkpinfo); 29 void wipe_archives 30 int write_image_to_floppy 31 int write_image_to_floppy_SUB 32 int write_iso_and_go_on 33 int write_final_iso_if_necessary 34 int call_growisofs 35 int make_afioballs_and_images_SINGLETHREAD 36 int archive_this_fileset_with_star (struct s_bkpinfo *bkpinfo, char *filelist, char *fname,37 35 void wipe_archives(char *d); 36 int write_image_to_floppy(char *device, char *datafile); 37 int write_image_to_floppy_SUB(char *device, char *datafile); 38 int write_iso_and_go_on(struct s_bkpinfo *bkpinfo, bool last_cd); 39 int write_final_iso_if_necessary(struct s_bkpinfo *bkpinfo); 40 int call_growisofs(struct s_bkpinfo *bkpinfo, char *destfile); 41 int make_afioballs_and_images_SINGLETHREAD(struct s_bkpinfo *bkpinfo); 42 int archive_this_fileset_with_star(struct s_bkpinfo *bkpinfo, 43 char *filelist, char *fname, int setno); -
trunk/mondo/mondo/common/libmondo-devices-EXT.h
r30 r59 1 1 /* 2 * $Id : libmondo-devices-EXT.h,v 1.4 2004/06/17 11:57:52 hugo Exp$2 * $Id$ 3 3 */ 4 4 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); 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, 10 char *mountpoint); 11 extern int find_cdrom_device(char *output, bool try_to_mount); 12 extern int find_dvd_device(char *output, bool try_to_mount); 13 extern long get_phys_size_of_drive(char *drive); 14 extern bool is_this_a_valid_disk_format(char *format); 15 extern bool is_this_device_mounted(char *device_raw); 16 extern int find_device_in_mountlist(struct mountlist_itself *mountlist, 17 char *device); 18 extern int mount_CDROM_here(char *device, char *mountpoint); 19 extern long long size_of_specific_device_in_mountlist(struct 20 mountlist_itself 21 *mountlist, 22 char *device); 23 extern char *where_is_root_mounted(void); 24 extern char *make_vn(char *file); 25 extern int kick_vn(char *vn); 26 extern char which_boot_loader(char *which_device); 22 27 23 28 24 29 25 extern int find_cdrw_device 30 extern int find_cdrw_device(char *cdrw_device); 26 31 27 32 28 extern int interactively_obtain_media_parameters_from_user(struct s_bkpinfo *, bool); 33 extern int interactively_obtain_media_parameters_from_user(struct s_bkpinfo 34 *, bool); 29 35 30 36 31 extern void make_fifo(char *store_name_here, char*stub);37 extern void make_fifo(char *store_name_here, char *stub); 32 38 33 39 34 extern void insist_on_this_cd_number (struct s_bkpinfo* bkpinfo, int cd_number_i_want); 40 extern void insist_on_this_cd_number(struct s_bkpinfo *bkpinfo, 41 int cd_number_i_want); 35 42 36 43 … … 38 45 39 46 40 extern int eject_device(char *);47 extern int eject_device(char *); 41 48 42 49 extern char *list_of_NFS_devices_and_mounts(); … … 46 53 47 54 48 extern bool set_dev_to_this_if_rx_OK(char *,char*);55 extern bool set_dev_to_this_if_rx_OK(char *, char *); 49 56 50 57 extern void retract_CD_tray_and_defeat_autorun(void); 51 58 52 extern bool does_string_exist_in_first_N_blocks (char *dev, char *str, int n); 59 extern bool does_string_exist_in_first_N_blocks(char *dev, char *str, 60 int n); 53 61 54 extern int inject_device(char *dev);62 extern int inject_device(char *dev); 55 63 extern bool does_nonMS_partition_exist(void); 56 extern char *resolve_softlinks_to_get_to_actual_device_file(char*incoming); 64 extern char *resolve_softlinks_to_get_to_actual_device_file(char 65 *incoming); 57 66 58 extern void set_g_cdrom_and_g_dvd_to_bkpinfo_value(struct s_bkpinfo*bkpinfo); 67 extern void set_g_cdrom_and_g_dvd_to_bkpinfo_value(struct s_bkpinfo 68 *bkpinfo); 59 69 60 70 extern bool is_dev_an_NTFS_dev(char *bigfile_fname); 61 71 62 72 extern char *which_partition_format(const char *drive); 63 -
trunk/mondo/mondo/common/libmondo-devices.c
r30 r59 1 1 /* libmondo-devices.c Subroutines for handling devices 2 $Id : libmondo-devices.c,v 1.26 2004/06/21 20:20:36 hugo Exp$2 $Id$ 3 3 . 4 4 … … 247 247 #elif linux 248 248 #define u64 unsigned long long 249 #include <linux/fs.h> 249 #include <linux/fs.h> /* for BLKGETSIZE64 */ 250 250 #include <linux/hdreg.h> 251 251 #endif 252 252 253 253 /*@unused@*/ 254 //static char cvsid[] = "$Id : libmondo-devices.c,v 1.26 2004/06/21 20:20:36 hugo Exp$";254 //static char cvsid[] = "$Id$"; 255 255 256 256 extern int g_current_media_number; … … 261 261 extern char *g_erase_tmpdir_and_scratchdir; 262 262 263 static char g_cdrw_drive_is_here[MAX_STR_LEN /4]="";264 static char g_cdrom_drive_is_here[MAX_STR_LEN /4]="";265 static char g_dvd_drive_is_here[MAX_STR_LEN /4]="";263 static char g_cdrw_drive_is_here[MAX_STR_LEN / 4] = ""; 264 static char g_cdrom_drive_is_here[MAX_STR_LEN / 4] = ""; 265 static char g_dvd_drive_is_here[MAX_STR_LEN / 4] = ""; 266 266 267 267 … … 270 270 * @ingroup globalGroup 271 271 */ 272 bool g_restoring_live_from_cd =FALSE;273 274 extern t_bkptype g_backup_media_type; 272 bool g_restoring_live_from_cd = FALSE; 273 274 extern t_bkptype g_backup_media_type; // set by main() 275 275 276 276 … … 279 279 void set_g_cdrom_and_g_dvd_to_bkpinfo_value(struct s_bkpinfo *bkpinfo) 280 280 { 281 strcpy(g_cdrom_drive_is_here, bkpinfo->media_device);// just in case282 strcpy(g_dvd_drive_is_here, bkpinfo->media_device);// just in case281 strcpy(g_cdrom_drive_is_here, bkpinfo->media_device); // just in case 282 strcpy(g_dvd_drive_is_here, bkpinfo->media_device); // just in case 283 283 } 284 284 … … 292 292 { 293 293 // log_it("rctada: Retracting all CD trays", __LINE__); 294 if (strlen(g_cdrom_drive_is_here)>0) 295 { inject_device(g_cdrom_drive_is_here); } 296 if (strlen(g_dvd_drive_is_here)>0) 297 { inject_device(g_dvd_drive_is_here); } 298 if (strlen(g_cdrw_drive_is_here)>0) 299 { inject_device(g_cdrw_drive_is_here); } 294 if (strlen(g_cdrom_drive_is_here) > 0) { 295 inject_device(g_cdrom_drive_is_here); 296 } 297 if (strlen(g_dvd_drive_is_here) > 0) { 298 inject_device(g_dvd_drive_is_here); 299 } 300 if (strlen(g_cdrw_drive_is_here) > 0) { 301 inject_device(g_cdrw_drive_is_here); 302 } 300 303 // log_it("rctada: killing autorun"); 301 304 // run_program_and_log_output("killall autorun", TRUE); 302 if (!run_program_and_log_output("ps | grep autorun | grep -v grep", 5)) 303 { 304 log_it("autorun detected; sleeping for 2 seconds"); 305 sleep(2); 306 } 307 log_it("rctada: Unmounting all CD drives", __LINE__); 308 run_program_and_log_output("umount /dev/cdr* /dev/dvd*", 5); 305 if (!run_program_and_log_output("ps | grep autorun | grep -v grep", 5)) { 306 log_it("autorun detected; sleeping for 2 seconds"); 307 sleep(2); 308 } 309 log_it("rctada: Unmounting all CD drives", __LINE__); 310 run_program_and_log_output("umount /dev/cdr* /dev/dvd*", 5); 309 311 } 310 312 … … 316 318 * @ingroup utilityGroup 317 319 */ 318 bool 319 am_I_in_disaster_recovery_mode (void) 320 { 321 char *tmp, *comment; 322 bool is_this_a_ramdisk = FALSE; 323 324 malloc_string(tmp); 325 malloc_string(comment); 326 strcpy(tmp, where_is_root_mounted()); 327 sprintf(comment, "root is mounted at %s\n", tmp); 328 log_msg(0, comment); 329 log_msg(0, "No, Schlomo, that doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().", tmp); 320 bool am_I_in_disaster_recovery_mode(void) 321 { 322 char *tmp, *comment; 323 bool is_this_a_ramdisk = FALSE; 324 325 malloc_string(tmp); 326 malloc_string(comment); 327 strcpy(tmp, where_is_root_mounted()); 328 sprintf(comment, "root is mounted at %s\n", tmp); 329 log_msg(0, comment); 330 log_msg(0, 331 "No, Schlomo, that doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().", 332 tmp); 330 333 331 334 #ifdef __FreeBSD__ 332 if (strstr(tmp, "/dev/md")) 333 { 334 is_this_a_ramdisk = TRUE; 335 } 335 if (strstr(tmp, "/dev/md")) { 336 is_this_a_ramdisk = TRUE; 337 } 336 338 #else 337 if (!strncmp(tmp, "/dev/ram", 8) || (!strncmp(tmp, "/dev/rd", 7) && !strcmp(tmp, "/dev/rd/") && strncmp(tmp, "/dev/rd/cd", 10)) || strstr(tmp, "rootfs") 338 || !strcmp(tmp, "/dev/root")) 339 { is_this_a_ramdisk = TRUE; } 340 else 341 { is_this_a_ramdisk = FALSE; } 342 #endif 343 344 if (is_this_a_ramdisk) 345 { 346 if (!does_file_exist("/THIS-IS-A-RAMDISK") && !does_file_exist("/tmp/mountlist.txt.sample")) 347 { 348 log_to_screen("Using /dev/root is stupid of you but I'll forgive you."); 349 is_this_a_ramdisk = FALSE; 350 } 351 } 352 if (does_file_exist("/THIS-IS-A-RAMDISK")) 353 { 354 is_this_a_ramdisk = TRUE; 355 } 356 paranoid_free(tmp); 357 paranoid_free(comment); 358 log_msg(1, "Is this a ramdisk? result = %d", is_this_a_ramdisk); 359 return(is_this_a_ramdisk); 339 if (!strncmp(tmp, "/dev/ram", 8) 340 || (!strncmp(tmp, "/dev/rd", 7) && !strcmp(tmp, "/dev/rd/") 341 && strncmp(tmp, "/dev/rd/cd", 10)) || strstr(tmp, "rootfs") 342 || !strcmp(tmp, "/dev/root")) { 343 is_this_a_ramdisk = TRUE; 344 } else { 345 is_this_a_ramdisk = FALSE; 346 } 347 #endif 348 349 if (is_this_a_ramdisk) { 350 if (!does_file_exist("/THIS-IS-A-RAMDISK") 351 && !does_file_exist("/tmp/mountlist.txt.sample")) { 352 log_to_screen 353 ("Using /dev/root is stupid of you but I'll forgive you."); 354 is_this_a_ramdisk = FALSE; 355 } 356 } 357 if (does_file_exist("/THIS-IS-A-RAMDISK")) { 358 is_this_a_ramdisk = TRUE; 359 } 360 paranoid_free(tmp); 361 paranoid_free(comment); 362 log_msg(1, "Is this a ramdisk? result = %d", is_this_a_ramdisk); 363 return (is_this_a_ramdisk); 360 364 } 361 365 … … 372 376 static char *bkptype_to_string(t_bkptype bt) 373 377 { 374 static char output[MAX_STR_LEN/4];375 switch(bt) 376 { 377 case none:strcpy(output, "none");378 static char output[MAX_STR_LEN / 4]; 379 switch (bt) { 380 case none: 381 strcpy(output, "none"); 378 382 break; 379 case iso: strcpy(output, "iso"); 383 case iso: 384 strcpy(output, "iso"); 380 385 break; 381 case cdr: strcpy(output, "cdr"); 386 case cdr: 387 strcpy(output, "cdr"); 382 388 break; 383 case cdrw: strcpy(output, "cdrw"); 389 case cdrw: 390 strcpy(output, "cdrw"); 384 391 break; 385 case cdstream: strcpy(output, "cdstream"); 392 case cdstream: 393 strcpy(output, "cdstream"); 386 394 break; 387 case nfs: strcpy(output, "nfs"); 395 case nfs: 396 strcpy(output, "nfs"); 388 397 break; 389 case tape: strcpy(output, "tape"); 398 case tape: 399 strcpy(output, "tape"); 390 400 break; 391 case udev: strcpy(output, "udev"); 401 case udev: 402 strcpy(output, "udev"); 392 403 break; 393 default: strcpy(output, "default"); 394 } 395 return(output); 404 default: 405 strcpy(output, "default"); 406 } 407 return (output); 396 408 } 397 409 … … 407 419 * @return the return value of the @c eject command. (0=success, nonzero=failure) 408 420 */ 409 int eject_device(char*dev) 410 { 411 char *command; 412 int res1=0, res2=0; 413 414 malloc_string(command); 415 416 if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type) && g_backup_media_type!=udev) 417 { 418 sprintf(command, "mt -f %s offline", dev); 419 res1 = run_program_and_log_output(command, 1); 420 } 421 else 422 { 423 res1 = 0; 424 } 421 int eject_device(char *dev) 422 { 423 char *command; 424 int res1 = 0, res2 = 0; 425 426 malloc_string(command); 427 428 if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type) 429 && g_backup_media_type != udev) { 430 sprintf(command, "mt -f %s offline", dev); 431 res1 = run_program_and_log_output(command, 1); 432 } else { 433 res1 = 0; 434 } 425 435 426 436 #ifdef __FreeBSD__ 427 if (strstr (dev, "acd")) { 428 sprintf (command, "cdcontrol -f %s eject", dev); 429 } else { 430 sprintf (command, "camcontrol eject `echo %s | sed 's|/dev/||'`", dev); 431 } 437 if (strstr(dev, "acd")) { 438 sprintf(command, "cdcontrol -f %s eject", dev); 439 } else { 440 sprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`", 441 dev); 442 } 432 443 #else 433 sprintf(command, "eject %s", dev); 434 #endif 435 436 log_msg(3, "Ejecting %s", dev); 437 res2 = run_program_and_log_output(command, 1); 438 paranoid_free(command); 439 if (res1 && res2) { return(1); } 440 else { return(0); } 444 sprintf(command, "eject %s", dev); 445 #endif 446 447 log_msg(3, "Ejecting %s", dev); 448 res2 = run_program_and_log_output(command, 1); 449 paranoid_free(command); 450 if (res1 && res2) { 451 return (1); 452 } else { 453 return (0); 454 } 441 455 } 442 456 … … 446 460 * @return 0 for success, nonzero for failure. 447 461 */ 448 int inject_device(char *dev)449 { 450 451 452 453 462 int inject_device(char *dev) 463 { 464 char *command; 465 int i; 466 467 malloc_string(command); 454 468 455 469 456 470 #ifdef __FreeBSD__ 457 if (strstr (dev, "acd")) { 458 sprintf (command, "cdcontrol -f %s close", dev); 459 } else { 460 sprintf (command, "camcontrol load `echo %s | sed 's|/dev/||'`", dev); 461 } 471 if (strstr(dev, "acd")) { 472 sprintf(command, "cdcontrol -f %s close", dev); 473 } else { 474 sprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`", 475 dev); 476 } 462 477 #else 463 464 #endif 465 466 467 return(i);478 sprintf(command, "eject -t %s", dev); 479 #endif 480 i = run_program_and_log_output(command, FALSE); 481 paranoid_free(command); 482 return (i); 468 483 } 469 484 … … 474 489 * @return TRUE if it exists, FALSE if it doesn't. 475 490 */ 476 bool 477 does_device_exist (char *device) 478 { 479 480 /*@ buffers ************************************************************/ 481 char *tmp; 482 483 malloc_string(tmp); 484 assert_string_is_neither_NULL_nor_zerolength(device); 485 486 sprintf (tmp, "ls %s > /dev/null 2> /dev/null", device); 487 488 paranoid_free(tmp); 489 if (system (tmp)) 490 { 491 return (FALSE); 492 } 493 else 494 { 495 return (TRUE); 496 } 491 bool does_device_exist(char *device) 492 { 493 494 /*@ buffers *********************************************************** */ 495 char *tmp; 496 497 malloc_string(tmp); 498 assert_string_is_neither_NULL_nor_zerolength(device); 499 500 sprintf(tmp, "ls %s > /dev/null 2> /dev/null", device); 501 502 paranoid_free(tmp); 503 if (system(tmp)) { 504 return (FALSE); 505 } else { 506 return (TRUE); 507 } 497 508 } 498 509 … … 502 513 * @return TRUE (there's a Linux/FreeBSD partition) or FALSE (Microsoft has taken over yet another innocent PC). 503 514 */ 504 bool 505 does_nonMS_partition_exist (void) 515 bool does_nonMS_partition_exist(void) 506 516 { 507 517 #if __FreeBSD__ 508 return !system ("for drive in /dev/ad? /dev/da?; do fdisk $drive | grep -q FreeBSD && exit 0; done; false"); 518 return 519 !system 520 ("for drive in /dev/ad? /dev/da?; do fdisk $drive | grep -q FreeBSD && exit 0; done; false"); 509 521 #else 510 return !system ("parted2fdisk -l 2>/dev/null | grep '^/dev/' | egrep -qv '(MS|DOS|FAT|NTFS)'"); 522 return 523 !system 524 ("parted2fdisk -l 2>/dev/null | grep '^/dev/' | egrep -qv '(MS|DOS|FAT|NTFS)'"); 511 525 #endif 512 526 } … … 518 532 * @return 0 if it exists, nonzero otherwise. 519 533 */ 520 int 521 does_partition_exist (const char *drive, int partno) 522 { 523 /*@ buffers *****************************************************/ 524 char *program; 525 char *incoming; 526 char *searchstr; 527 char *tmp; 528 529 /*@ ints ********************************************************/ 530 int res = 0; 531 532 /*@ pointers ****************************************************/ 533 FILE *fin; 534 535 536 /*@ end vars ****************************************************/ 537 assert_string_is_neither_NULL_nor_zerolength(drive); 538 assert(partno>=0 && partno<999); 539 540 malloc_string(program); 541 malloc_string(incoming); 542 malloc_string(searchstr); 543 malloc_string(tmp); 534 int does_partition_exist(const char *drive, int partno) 535 { 536 /*@ buffers **************************************************** */ 537 char *program; 538 char *incoming; 539 char *searchstr; 540 char *tmp; 541 542 /*@ ints ******************************************************* */ 543 int res = 0; 544 545 /*@ pointers *************************************************** */ 546 FILE *fin; 547 548 549 /*@ end vars *************************************************** */ 550 assert_string_is_neither_NULL_nor_zerolength(drive); 551 assert(partno >= 0 && partno < 999); 552 553 malloc_string(program); 554 malloc_string(incoming); 555 malloc_string(searchstr); 556 malloc_string(tmp); 544 557 545 558 #ifdef __FreeBSD__ 546 // We assume here that this is running from mondorestore. (It is.) 547 sprintf (program, "ls %s >/dev/null 2>&1", drive, build_partition_name (tmp, drive, partno)); 548 return system (program); 559 // We assume here that this is running from mondorestore. (It is.) 560 sprintf(program, "ls %s >/dev/null 2>&1", drive, 561 build_partition_name(tmp, drive, partno)); 562 return system(program); 549 563 #else 550 tmp[0] = '\0'; 551 #endif 552 553 sprintf (program, "parted2fdisk -l %s 2> /dev/null", drive); 554 fin = popen (program, "r"); 555 if (!fin) 556 { 557 log_it("program=%s", program); 558 log_OS_error("Cannot popen-in program"); 559 return (0); 560 } 561 (void) build_partition_name (searchstr, drive, partno); 562 strcat(searchstr, " "); 563 for (res = 0; !res && fgets (incoming, MAX_STR_LEN - 1, fin); ) 564 { 565 if (strstr (incoming, searchstr)) 566 { 567 res = 1; 568 } 569 } 570 if (pclose (fin)) { log_OS_error("Cannot pclose fin"); } 571 paranoid_free(program); 572 paranoid_free(incoming); 573 paranoid_free(searchstr); 574 paranoid_free(tmp); 575 return (res); 564 tmp[0] = '\0'; 565 #endif 566 567 sprintf(program, "parted2fdisk -l %s 2> /dev/null", drive); 568 fin = popen(program, "r"); 569 if (!fin) { 570 log_it("program=%s", program); 571 log_OS_error("Cannot popen-in program"); 572 return (0); 573 } 574 (void) build_partition_name(searchstr, drive, partno); 575 strcat(searchstr, " "); 576 for (res = 0; !res && fgets(incoming, MAX_STR_LEN - 1, fin);) { 577 if (strstr(incoming, searchstr)) { 578 res = 1; 579 } 580 } 581 if (pclose(fin)) { 582 log_OS_error("Cannot pclose fin"); 583 } 584 paranoid_free(program); 585 paranoid_free(incoming); 586 paranoid_free(searchstr); 587 paranoid_free(tmp); 588 return (res); 576 589 } 577 590 … … 586 599 * @return TRUE if it exists, FALSE if it doesn't. 587 600 */ 588 bool 589 does_string_exist_in_boot_block (char *dev, char *str) 590 { 591 /*@ buffers *****************************************************/ 592 char *command; 593 594 /*@ end vars ****************************************************/ 595 int i; 596 597 assert_string_is_neither_NULL_nor_zerolength(dev); 598 assert_string_is_neither_NULL_nor_zerolength(str); 599 600 malloc_string(command); 601 sprintf (command, 602 "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 603 dev, str); 604 i = system(command); 605 paranoid_free(command); 606 if (i) 607 { 608 return (FALSE); 609 } 610 else 611 { 612 return (TRUE); 613 } 601 bool does_string_exist_in_boot_block(char *dev, char *str) 602 { 603 /*@ buffers **************************************************** */ 604 char *command; 605 606 /*@ end vars *************************************************** */ 607 int i; 608 609 assert_string_is_neither_NULL_nor_zerolength(dev); 610 assert_string_is_neither_NULL_nor_zerolength(str); 611 612 malloc_string(command); 613 sprintf(command, 614 "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 615 dev, str); 616 i = system(command); 617 paranoid_free(command); 618 if (i) { 619 return (FALSE); 620 } else { 621 return (TRUE); 622 } 614 623 } 615 624 … … 621 630 * @param n The number of 512-byte sectors to search. 622 631 */ 623 bool 624 does_string_exist_in_first_N_blocks (char *dev, char *str, int n) 625 { 626 /*@ buffers *****************************************************/ 627 char *command; 628 /*@ end vars ****************************************************/ 629 int i; 630 631 malloc_string(command); 632 sprintf (command, 633 "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 634 dev, n, str); 635 i = system(command); 636 paranoid_free(command); 637 if (i) 638 { 639 return (FALSE); 640 } 641 else 642 { 643 return (TRUE); 644 } 632 bool does_string_exist_in_first_N_blocks(char *dev, char *str, int n) 633 { 634 /*@ buffers **************************************************** */ 635 char *command; 636 /*@ end vars *************************************************** */ 637 int i; 638 639 malloc_string(command); 640 sprintf(command, 641 "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 642 dev, n, str); 643 i = system(command); 644 paranoid_free(command); 645 if (i) { 646 return (FALSE); 647 } else { 648 return (TRUE); 649 } 645 650 } 646 651 … … 655 660 * @see mount_CDROM_here 656 661 */ 657 int 658 find_and_mount_actual_cd (struct s_bkpinfo *bkpinfo, char *mountpoint) 659 { 660 /*@ buffers ******************************************************/ 661 662 /*@ int's *******************************************************/ 663 int res; 664 char *dev; 665 666 /*@ end vars *****************************************************/ 667 668 malloc_string(dev); 669 assert(bkpinfo!=NULL); 670 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 671 672 if (g_backup_media_type == dvd) 673 { 674 strcpy(dev, g_dvd_drive_is_here); 675 if (!dev[0]) 676 { find_dvd_device(dev,FALSE); } 677 } 678 else 679 { 680 strcpy(dev, g_cdrom_drive_is_here); 681 if (!dev[0]) 682 { find_cdrom_device(dev,FALSE); } 683 } 684 685 if (bkpinfo->backup_media_type != iso) 686 { retract_CD_tray_and_defeat_autorun(); } 687 688 if (!dev[0] || (res=mount_CDROM_here (dev, mountpoint))) 689 { 690 if (!popup_and_get_string 662 int find_and_mount_actual_cd(struct s_bkpinfo *bkpinfo, char *mountpoint) 663 { 664 /*@ buffers ***************************************************** */ 665 666 /*@ int's ****************************************************** */ 667 int res; 668 char *dev; 669 670 /*@ end vars **************************************************** */ 671 672 malloc_string(dev); 673 assert(bkpinfo != NULL); 674 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 675 676 if (g_backup_media_type == dvd) { 677 strcpy(dev, g_dvd_drive_is_here); 678 if (!dev[0]) { 679 find_dvd_device(dev, FALSE); 680 } 681 } else { 682 strcpy(dev, g_cdrom_drive_is_here); 683 if (!dev[0]) { 684 find_cdrom_device(dev, FALSE); 685 } 686 } 687 688 if (bkpinfo->backup_media_type != iso) { 689 retract_CD_tray_and_defeat_autorun(); 690 } 691 692 if (!dev[0] || (res = mount_CDROM_here(dev, mountpoint))) { 693 if (!popup_and_get_string 691 694 ("CD-ROM device", "Please enter your CD-ROM's /dev device", 692 dev, MAX_STR_LEN/4)) 693 { res = 1; } 694 else 695 { res=mount_CDROM_here (dev, mountpoint); } 696 } 697 if (res) { log_msg(1, "mount failed"); } 698 else { log_msg(1, "mount succeeded with %s", dev); } 699 paranoid_free(dev); 700 return (res); 695 dev, MAX_STR_LEN / 4)) { 696 res = 1; 697 } else { 698 res = mount_CDROM_here(dev, mountpoint); 699 } 700 } 701 if (res) { 702 log_msg(1, "mount failed"); 703 } else { 704 log_msg(1, "mount succeeded with %s", dev); 705 } 706 paranoid_free(dev); 707 return (res); 701 708 } 702 709 … … 717 724 * @return 0 for success, nonzero for failure. 718 725 */ 719 int 720 find_cdrw_device (char *cdrw_device) 721 { 722 /*@ buffers *************************/ 723 char *comment; 724 char *tmp; 725 char *cdr_exe; 726 char *command; 727 728 malloc_string(comment); 729 malloc_string(tmp); 730 malloc_string(cdr_exe); 731 malloc_string(command); 732 if (g_cdrw_drive_is_here[0]) 733 { 734 strcpy(cdrw_device, g_cdrw_drive_is_here); 735 log_msg(3, "Been there, done that. Returning %s", cdrw_device); 736 paranoid_free(comment); 737 paranoid_free(tmp); 738 paranoid_free(cdr_exe); 739 paranoid_free(command); 740 return(0); 741 } 742 if (g_backup_media_type == dvd) 743 { 744 log_msg(1, "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?"); 745 paranoid_free(comment); 746 paranoid_free(tmp); 747 paranoid_free(cdr_exe); 748 paranoid_free(command); 749 return(1); 750 } 751 run_program_and_log_output("insmod ide-scsi", -1); 752 if (find_home_of_exe("cdrecord")) 753 { strcpy(cdr_exe, "cdrecord"); } 754 else 755 { strcpy(cdr_exe, "dvdrecord"); } 756 tmp[0]='\0'; 757 if (find_home_of_exe(cdr_exe)) 758 { 759 sprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep CD | cut -d' ' -f2 | head -n1", cdr_exe); 760 strcpy (tmp, call_program_and_get_last_line_of_output(command)); 761 } 762 if (strlen (tmp) < 2) 763 { 764 paranoid_free(comment); 765 paranoid_free(tmp); 766 paranoid_free(cdr_exe); 767 paranoid_free(command); 768 return 1; 769 } 770 else 771 { 772 strcpy (cdrw_device, tmp); 773 sprintf (comment, "Found CDRW device - %s", cdrw_device); 774 log_it (comment); 775 strcpy (g_cdrw_drive_is_here, cdrw_device); 776 paranoid_free(comment); 777 paranoid_free(tmp); 778 paranoid_free(cdr_exe); 779 paranoid_free(command); 780 return (0); 781 } 726 int find_cdrw_device(char *cdrw_device) 727 { 728 /*@ buffers ************************ */ 729 char *comment; 730 char *tmp; 731 char *cdr_exe; 732 char *command; 733 734 malloc_string(comment); 735 malloc_string(tmp); 736 malloc_string(cdr_exe); 737 malloc_string(command); 738 if (g_cdrw_drive_is_here[0]) { 739 strcpy(cdrw_device, g_cdrw_drive_is_here); 740 log_msg(3, "Been there, done that. Returning %s", cdrw_device); 741 paranoid_free(comment); 742 paranoid_free(tmp); 743 paranoid_free(cdr_exe); 744 paranoid_free(command); 745 return (0); 746 } 747 if (g_backup_media_type == dvd) { 748 log_msg(1, 749 "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?"); 750 paranoid_free(comment); 751 paranoid_free(tmp); 752 paranoid_free(cdr_exe); 753 paranoid_free(command); 754 return (1); 755 } 756 run_program_and_log_output("insmod ide-scsi", -1); 757 if (find_home_of_exe("cdrecord")) { 758 strcpy(cdr_exe, "cdrecord"); 759 } else { 760 strcpy(cdr_exe, "dvdrecord"); 761 } 762 tmp[0] = '\0'; 763 if (find_home_of_exe(cdr_exe)) { 764 sprintf(command, 765 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep CD | cut -d' ' -f2 | head -n1", 766 cdr_exe); 767 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 768 } 769 if (strlen(tmp) < 2) { 770 paranoid_free(comment); 771 paranoid_free(tmp); 772 paranoid_free(cdr_exe); 773 paranoid_free(command); 774 return 1; 775 } else { 776 strcpy(cdrw_device, tmp); 777 sprintf(comment, "Found CDRW device - %s", cdrw_device); 778 log_it(comment); 779 strcpy(g_cdrw_drive_is_here, cdrw_device); 780 paranoid_free(comment); 781 paranoid_free(tmp); 782 paranoid_free(cdr_exe); 783 paranoid_free(command); 784 return (0); 785 } 782 786 } 783 787 … … 794 798 * @return 0 for success, nonzero for failure. 795 799 */ 796 int 797 find_cdrom_device (char *output, bool try_to_mount) 798 { 799 /*@ pointers *****************************************************/ 800 FILE *fin; 801 char *p; 802 char *q; 803 char *r; 804 int retval=0; 805 806 /*@ bool's *******************************************************/ 807 bool found_it = FALSE; 808 809 /*@ buffers ******************************************************/ 810 char *tmp; 811 char *cdr_exe; 812 char *phrase_one; 813 char *phrase_two; 814 char *command; 815 char *dvd_last_resort; 816 char *mountpoint; 817 static char the_last_place_i_found_it[MAX_STR_LEN] = ""; 818 819 /*@ intialize ****************************************************/ 820 malloc_string(tmp); 821 malloc_string(cdr_exe); 822 malloc_string(phrase_one); 823 malloc_string(phrase_two); 824 malloc_string(command); 825 malloc_string(dvd_last_resort); 826 malloc_string(mountpoint); 827 828 output[0] = '\0'; 829 phrase_one[0] = '\0'; 830 phrase_two[0] = '\0'; 831 dvd_last_resort[0] = '\0'; 832 833 /*@ end vars *****************************************************/ 834 835 if (g_cdrom_drive_is_here[0] && !isdigit(g_cdrom_drive_is_here[0])) 836 { 837 strcpy(output, g_cdrom_drive_is_here); 838 log_msg(3, "Been there, done that. Returning %s", output); 839 retval=0; 840 goto end_of_find_cdrom_device; 841 } 842 if (the_last_place_i_found_it[0]!='\0' && !try_to_mount) 843 { 844 strcpy(output, the_last_place_i_found_it); 845 log_msg(3, "find_cdrom_device() --- returning last found location - '%s'", output); 846 retval=0; 847 goto end_of_find_cdrom_device; 848 } 849 850 sprintf(mountpoint,"/tmp/cd.%d", (int)(random()%32767)); 851 make_hole_for_dir(mountpoint); 852 853 if (find_home_of_exe("cdrecord")) 854 { strcpy(cdr_exe, "cdrecord"); } 855 else 856 { strcpy(cdr_exe, "dvdrecord"); } 857 tmp[0]='\0'; 858 if (!find_home_of_exe(cdr_exe)) 859 { 860 strcpy(output, "/dev/cdrom"); 861 log_msg(4, "Can't find cdrecord; assuming %s", output); 862 if (!does_device_exist(output)) 863 { 864 log_msg(4, "That didn't work. Sorry."); 865 retval=1; 866 goto end_of_find_cdrom_device; 867 } 868 else 869 { 870 retval=0; 871 goto end_of_find_cdrom_device; 872 } 873 } 874 875 sprintf(command, "%s -scanbus 2> /dev/null", cdr_exe); 876 fin = popen (command, "r"); 877 if (!fin) { log_msg(4, "command=%s", command); log_OS_error("Cannot popen command"); return (1); } 878 for (fgets (tmp, MAX_STR_LEN, fin); !feof (fin); 879 fgets (tmp, MAX_STR_LEN, fin)) 880 { 881 p = strchr (tmp, '\''); 882 if (p) 883 { 884 q = strchr (++p, '\''); 885 if (q) 886 { 887 for (r = q; *(r - 1) == ' '; r--); 888 *r = '\0'; 889 strcpy (phrase_one, p); 890 p = strchr (++q, '\''); 891 if (p) 892 { 893 q = strchr (++p, '\''); 894 if (q) 895 { 896 while (*(q - 1) == ' ') 897 { 898 q--; 899 } 900 *q = '\0'; 901 strcpy (phrase_two, p); 902 } 903 } 904 } 905 } 906 } 907 paranoid_pclose(fin); 800 int find_cdrom_device(char *output, bool try_to_mount) 801 { 802 /*@ pointers **************************************************** */ 803 FILE *fin; 804 char *p; 805 char *q; 806 char *r; 807 int retval = 0; 808 809 /*@ bool's ****************************************************** */ 810 bool found_it = FALSE; 811 812 /*@ buffers ***************************************************** */ 813 char *tmp; 814 char *cdr_exe; 815 char *phrase_one; 816 char *phrase_two; 817 char *command; 818 char *dvd_last_resort; 819 char *mountpoint; 820 static char the_last_place_i_found_it[MAX_STR_LEN] = ""; 821 822 /*@ intialize *************************************************** */ 823 malloc_string(tmp); 824 malloc_string(cdr_exe); 825 malloc_string(phrase_one); 826 malloc_string(phrase_two); 827 malloc_string(command); 828 malloc_string(dvd_last_resort); 829 malloc_string(mountpoint); 830 831 output[0] = '\0'; 832 phrase_one[0] = '\0'; 833 phrase_two[0] = '\0'; 834 dvd_last_resort[0] = '\0'; 835 836 /*@ end vars **************************************************** */ 837 838 if (g_cdrom_drive_is_here[0] && !isdigit(g_cdrom_drive_is_here[0])) { 839 strcpy(output, g_cdrom_drive_is_here); 840 log_msg(3, "Been there, done that. Returning %s", output); 841 retval = 0; 842 goto end_of_find_cdrom_device; 843 } 844 if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) { 845 strcpy(output, the_last_place_i_found_it); 846 log_msg(3, 847 "find_cdrom_device() --- returning last found location - '%s'", 848 output); 849 retval = 0; 850 goto end_of_find_cdrom_device; 851 } 852 853 sprintf(mountpoint, "/tmp/cd.%d", (int) (random() % 32767)); 854 make_hole_for_dir(mountpoint); 855 856 if (find_home_of_exe("cdrecord")) { 857 strcpy(cdr_exe, "cdrecord"); 858 } else { 859 strcpy(cdr_exe, "dvdrecord"); 860 } 861 tmp[0] = '\0'; 862 if (!find_home_of_exe(cdr_exe)) { 863 strcpy(output, "/dev/cdrom"); 864 log_msg(4, "Can't find cdrecord; assuming %s", output); 865 if (!does_device_exist(output)) { 866 log_msg(4, "That didn't work. Sorry."); 867 retval = 1; 868 goto end_of_find_cdrom_device; 869 } else { 870 retval = 0; 871 goto end_of_find_cdrom_device; 872 } 873 } 874 875 sprintf(command, "%s -scanbus 2> /dev/null", cdr_exe); 876 fin = popen(command, "r"); 877 if (!fin) { 878 log_msg(4, "command=%s", command); 879 log_OS_error("Cannot popen command"); 880 return (1); 881 } 882 for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin); 883 fgets(tmp, MAX_STR_LEN, fin)) { 884 p = strchr(tmp, '\''); 885 if (p) { 886 q = strchr(++p, '\''); 887 if (q) { 888 for (r = q; *(r - 1) == ' '; r--); 889 *r = '\0'; 890 strcpy(phrase_one, p); 891 p = strchr(++q, '\''); 892 if (p) { 893 q = strchr(++p, '\''); 894 if (q) { 895 while (*(q - 1) == ' ') { 896 q--; 897 } 898 *q = '\0'; 899 strcpy(phrase_two, p); 900 } 901 } 902 } 903 } 904 } 905 paranoid_pclose(fin); 908 906 909 907 #ifndef __FreeBSD__ 910 if (strlen(phrase_two)==0) 911 { log_msg(4, "Not running phase two. String is empty."); } 912 else 913 { 914 sprintf (command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two); 915 fin = popen (command, "r"); 916 if (!fin) 917 { 918 log_msg(4, "Cannot run 2nd command - non-fatal, fortunately"); 919 } 920 else 921 { 922 for (fgets (tmp, MAX_STR_LEN, fin); !feof (fin); fgets (tmp, MAX_STR_LEN, fin)) 923 { 924 log_msg(5, "--> '%s'", tmp); 925 if (tmp[0] != ' ' && tmp[1] != ' ') 926 { 927 p = strchr (tmp, ':'); 928 if (p) 929 { 930 *p = '\0'; 931 if (strstr(tmp, "DVD")) 932 { 933 sprintf(dvd_last_resort, "/dev/%s", tmp); 934 log_msg(4, "Ignoring '%s' because it's a DVD drive", tmp); 935 } 936 else 937 { 938 sprintf (output, "/dev/%s", tmp); 939 found_it = TRUE; 940 } 941 } 942 } 943 } 944 paranoid_pclose(fin); 945 } 946 } 908 if (strlen(phrase_two) == 0) { 909 log_msg(4, "Not running phase two. String is empty."); 910 } else { 911 sprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two); 912 fin = popen(command, "r"); 913 if (!fin) { 914 log_msg(4, "Cannot run 2nd command - non-fatal, fortunately"); 915 } else { 916 for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin); 917 fgets(tmp, MAX_STR_LEN, fin)) { 918 log_msg(5, "--> '%s'", tmp); 919 if (tmp[0] != ' ' && tmp[1] != ' ') { 920 p = strchr(tmp, ':'); 921 if (p) { 922 *p = '\0'; 923 if (strstr(tmp, "DVD")) { 924 sprintf(dvd_last_resort, "/dev/%s", tmp); 925 log_msg(4, 926 "Ignoring '%s' because it's a DVD drive", 927 tmp); 928 } else { 929 sprintf(output, "/dev/%s", tmp); 930 found_it = TRUE; 931 } 932 } 933 } 934 } 935 paranoid_pclose(fin); 936 } 937 } 947 938 948 939 #endif 949 940 #ifdef __FreeBSD__ 950 if (!found_it) 951 { log_msg(4, "OK, approach 2"); if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom"))) 952 { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom1"))) 953 { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/dvd"))) 954 { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/acd0"))) 955 { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cd01"))) 956 { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/acd1"))) 957 { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cd1"))) 958 { retval=1; goto end_of_find_cdrom_device; } 959 } } } } } } } 941 if (!found_it) { 942 log_msg(4, "OK, approach 2"); 943 if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom"))) { 944 if (! 945 (found_it = 946 set_dev_to_this_if_rx_OK(output, "/dev/cdrom1"))) { 947 if (! 948 (found_it = 949 set_dev_to_this_if_rx_OK(output, "/dev/dvd"))) { 950 if (! 951 (found_it = 952 set_dev_to_this_if_rx_OK(output, "/dev/acd0"))) { 953 if (! 954 (found_it = 955 set_dev_to_this_if_rx_OK(output, 956 "/dev/cd01"))) { 957 if (! 958 (found_it = 959 set_dev_to_this_if_rx_OK(output, 960 "/dev/acd1"))) { 961 if (! 962 (found_it = 963 set_dev_to_this_if_rx_OK(output, 964 "/dev/cd1"))) 965 { 966 retval = 1; 967 goto end_of_find_cdrom_device; 968 } 969 } 970 } 971 } 972 } 973 } 974 } 975 } 960 976 #else 961 if (!found_it && strlen(dvd_last_resort)>0) 962 { 963 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", dvd_last_resort); 964 strcpy(output, dvd_last_resort); 965 found_it = TRUE; 966 } 967 if (found_it) 968 { 969 sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", strrchr(output,'/')+1); 970 if (system(tmp) == 0) 971 { 972 log_msg(4, "%s is not right. It's being SCSI-emulated. Continuing.", output); 973 found_it = FALSE; 974 output[0] = '\0'; 975 } 976 } 977 978 if (found_it) 979 { 980 log_msg(4, "(find_cdrom_device) --> '%s'", output); 981 if (!does_device_exist(output)) { found_it=FALSE; log_msg(4, "OK, I was wrong, I haven't found it... yet."); } 982 } 983 984 if (!found_it) 985 { log_msg(4, "OK, approach 2"); if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/scd0"))) 986 { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/sr0" ))) 987 { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom"))) 988 { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom0"))) 989 { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom1"))) 990 { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/sr1"))) 991 { if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/dvd"))) 992 { if (!(found_it = set_dev_to_this_if_rx_OK(output, g_cdrw_drive_is_here))) 993 { retval=1; goto end_of_find_cdrom_device; } 994 } } } } } } } } 995 #endif 996 997 if (found_it && try_to_mount) 998 { 999 if (mount_CDROM_here (output, mountpoint)) 1000 { 1001 log_msg(4, "[Cardigans] I've changed my mind"); 1002 found_it = FALSE; 1003 } 1004 else 1005 { 1006 sprintf(tmp, "%s/archives", mountpoint); 1007 if (!does_file_exist(tmp)) 1008 { 1009 log_msg(4, "[Cardigans] I'll take it back"); 1010 found_it = FALSE; 1011 } 1012 else 1013 { 1014 sprintf(command, "umount %s", output); 1015 paranoid_system(command); 1016 log_msg(4, "I'm confident the Mondo CD is in %s", output); 1017 } 1018 } 1019 } 1020 unlink(mountpoint); 1021 1022 if (found_it) 1023 { 1024 if (!does_file_exist(output)) { log_msg(3, "I still haven't found it."); return(1); } 1025 log_msg(3, "(find_cdrom_device) --> '%s'", output); 1026 strcpy(the_last_place_i_found_it, output); 1027 strcpy(g_cdrom_drive_is_here, output); 1028 retval=0; 1029 goto end_of_find_cdrom_device; 1030 } 1031 1032 sprintf(command, "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", cdr_exe, g_cdrw_drive_is_here); 1033 log_msg(1, "command=%s", command); 1034 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 1035 if (tmp[0]) 1036 { 1037 strcpy(output, tmp); 1038 log_msg(4, "Finally found it at %s", output); 1039 retval=0; 1040 goto end_of_find_cdrom_device; 1041 } 1042 else 1043 { 1044 log_msg(4, "Still couldn't find it."); 1045 retval=1; 1046 goto end_of_find_cdrom_device; 1047 } 1048 end_of_find_cdrom_device: 1049 paranoid_free(tmp); 1050 paranoid_free(cdr_exe); 1051 paranoid_free(phrase_one); 1052 paranoid_free(phrase_two); 1053 paranoid_free(command); 1054 paranoid_free(dvd_last_resort); 1055 paranoid_free(mountpoint); 1056 return(retval); 1057 } 1058 1059 1060 1061 1062 1063 int find_dvd_device(char*output, bool try_to_mount) 1064 { 1065 char *command; 1066 char *tmp; 1067 int retval=0, devno=-1; 1068 1069 malloc_string(command); 1070 malloc_string(tmp); 1071 1072 if (g_dvd_drive_is_here[0]) 1073 { 1074 strcpy(output, g_dvd_drive_is_here); 1075 log_msg(3, "Been there, done that. Returning %s", output); 1076 return(0); 1077 } 1078 1079 sprintf(tmp, call_program_and_get_last_line_of_output 1080 ( 1081 "dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1" 1082 ) 977 if (!found_it && strlen(dvd_last_resort) > 0) { 978 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", 979 dvd_last_resort); 980 strcpy(output, dvd_last_resort); 981 found_it = TRUE; 982 } 983 if (found_it) { 984 sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", 985 strrchr(output, '/') + 1); 986 if (system(tmp) == 0) { 987 log_msg(4, 988 "%s is not right. It's being SCSI-emulated. Continuing.", 989 output); 990 found_it = FALSE; 991 output[0] = '\0'; 992 } 993 } 994 995 if (found_it) { 996 log_msg(4, "(find_cdrom_device) --> '%s'", output); 997 if (!does_device_exist(output)) { 998 found_it = FALSE; 999 log_msg(4, "OK, I was wrong, I haven't found it... yet."); 1000 } 1001 } 1002 1003 if (!found_it) { 1004 log_msg(4, "OK, approach 2"); 1005 if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/scd0"))) { 1006 if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/sr0"))) { 1007 if (! 1008 (found_it = 1009 set_dev_to_this_if_rx_OK(output, "/dev/cdrom"))) { 1010 if (! 1011 (found_it = 1012 set_dev_to_this_if_rx_OK(output, 1013 "/dev/cdrom0"))) { 1014 if (! 1015 (found_it = 1016 set_dev_to_this_if_rx_OK(output, 1017 "/dev/cdrom1"))) { 1018 if (! 1019 (found_it = 1020 set_dev_to_this_if_rx_OK(output, 1021 "/dev/sr1"))) { 1022 if (! 1023 (found_it = 1024 set_dev_to_this_if_rx_OK(output, 1025 "/dev/dvd"))) 1026 { 1027 if (! 1028 (found_it = 1029 set_dev_to_this_if_rx_OK(output, 1030 g_cdrw_drive_is_here))) 1031 { 1032 retval = 1; 1033 goto end_of_find_cdrom_device; 1034 } 1035 } 1036 } 1037 } 1038 } 1039 } 1040 } 1041 } 1042 } 1043 #endif 1044 1045 if (found_it && try_to_mount) { 1046 if (mount_CDROM_here(output, mountpoint)) { 1047 log_msg(4, "[Cardigans] I've changed my mind"); 1048 found_it = FALSE; 1049 } else { 1050 sprintf(tmp, "%s/archives", mountpoint); 1051 if (!does_file_exist(tmp)) { 1052 log_msg(4, "[Cardigans] I'll take it back"); 1053 found_it = FALSE; 1054 } else { 1055 sprintf(command, "umount %s", output); 1056 paranoid_system(command); 1057 log_msg(4, "I'm confident the Mondo CD is in %s", output); 1058 } 1059 } 1060 } 1061 unlink(mountpoint); 1062 1063 if (found_it) { 1064 if (!does_file_exist(output)) { 1065 log_msg(3, "I still haven't found it."); 1066 return (1); 1067 } 1068 log_msg(3, "(find_cdrom_device) --> '%s'", output); 1069 strcpy(the_last_place_i_found_it, output); 1070 strcpy(g_cdrom_drive_is_here, output); 1071 retval = 0; 1072 goto end_of_find_cdrom_device; 1073 } 1074 1075 sprintf(command, 1076 "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", 1077 cdr_exe, g_cdrw_drive_is_here); 1078 log_msg(1, "command=%s", command); 1079 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 1080 if (tmp[0]) { 1081 strcpy(output, tmp); 1082 log_msg(4, "Finally found it at %s", output); 1083 retval = 0; 1084 goto end_of_find_cdrom_device; 1085 } else { 1086 log_msg(4, "Still couldn't find it."); 1087 retval = 1; 1088 goto end_of_find_cdrom_device; 1089 } 1090 end_of_find_cdrom_device: 1091 paranoid_free(tmp); 1092 paranoid_free(cdr_exe); 1093 paranoid_free(phrase_one); 1094 paranoid_free(phrase_two); 1095 paranoid_free(command); 1096 paranoid_free(dvd_last_resort); 1097 paranoid_free(mountpoint); 1098 return (retval); 1099 } 1100 1101 1102 1103 1104 1105 int find_dvd_device(char *output, bool try_to_mount) 1106 { 1107 char *command; 1108 char *tmp; 1109 int retval = 0, devno = -1; 1110 1111 malloc_string(command); 1112 malloc_string(tmp); 1113 1114 if (g_dvd_drive_is_here[0]) { 1115 strcpy(output, g_dvd_drive_is_here); 1116 log_msg(3, "Been there, done that. Returning %s", output); 1117 return (0); 1118 } 1119 1120 sprintf(tmp, call_program_and_get_last_line_of_output 1121 ("dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1") 1083 1122 ); 1084 log_msg(5, "tmp = '%s'", tmp); 1085 if (!tmp[0]) sprintf (tmp, call_program_and_get_last_line_of_output 1086 ( 1087 "cdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1" 1088 ) 1089 ); 1090 if (tmp[0]) 1091 { 1092 devno=atoi(tmp) - 1; 1093 } 1094 if (devno>=0) 1095 { 1096 retval=0; 1097 sprintf(output, "/dev/scd%d", devno); 1098 strcpy(g_dvd_drive_is_here, output); 1099 log_msg(2, "I think DVD is at %s", output); 1100 } 1101 else 1102 { 1103 log_msg(2,"I cannot find DVD"); 1104 retval=1; 1105 } 1106 1107 if (try_to_mount) 1108 { 1109 log_msg(1, "Ignoring the fact that try_to_mount==TRUE"); 1110 } 1111 return(retval); 1123 log_msg(5, "tmp = '%s'", tmp); 1124 if (!tmp[0]) 1125 sprintf(tmp, call_program_and_get_last_line_of_output 1126 ("cdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1") 1127 ); 1128 if (tmp[0]) { 1129 devno = atoi(tmp) - 1; 1130 } 1131 if (devno >= 0) { 1132 retval = 0; 1133 sprintf(output, "/dev/scd%d", devno); 1134 strcpy(g_dvd_drive_is_here, output); 1135 log_msg(2, "I think DVD is at %s", output); 1136 } else { 1137 log_msg(2, "I cannot find DVD"); 1138 retval = 1; 1139 } 1140 1141 if (try_to_mount) { 1142 log_msg(1, "Ignoring the fact that try_to_mount==TRUE"); 1143 } 1144 return (retval); 1112 1145 } 1113 1146 … … 1124 1157 * @return size in megabytes. 1125 1158 */ 1126 long 1127 get_phys_size_of_drive (char *drive) 1128 { 1129 int fd; 1159 long get_phys_size_of_drive(char *drive) 1160 { 1161 int fd; 1130 1162 #if linux 1131 unsigned long long s=0;1132 int fileid, cylinders =0, cylindersleft=0;1133 int cylindersize =0;1163 unsigned long long s = 0; 1164 int fileid, cylinders = 0, cylindersleft = 0; 1165 int cylindersize = 0; 1134 1166 int gotgeo = 0; 1135 1167 1136 1137 1168 1169 struct hd_geometry hdgeo; 1138 1170 #elif __FreeBSD__ 1139 1140 #endif 1141 1142 long outvalA=-1;1143 long outvalB=-1;1144 long outvalC=-1;1145 1146 if ((fd = open(drive, O_RDONLY)) != -1) {1147 if (ioctl(fd,1171 off_t s; 1172 #endif 1173 1174 long outvalA = -1; 1175 long outvalB = -1; 1176 long outvalC = -1; 1177 1178 if ((fd = open(drive, O_RDONLY)) != -1) { 1179 if (ioctl(fd, 1148 1180 #if linux 1149 1150 1151 1152 1153 1181 #ifdef BLKGETSIZE64 1182 BLKGETSIZE64, 1183 #else 1184 BLKGETSIZE, 1185 #endif 1154 1186 #elif __FreeBSD__ 1155 1156 #endif 1157 1158 close(fd);1159 1160 1187 DIOCGMEDIASIZE, 1188 #endif 1189 &s) != -1) { 1190 close(fd); 1191 // s>>11 works for older disks but not for newer ones 1192 outvalB = 1161 1193 #if linux 1162 #ifdef BLKGETSIZE64 1163 s >> 20 1164 #else 1165 s >> 11 1166 #endif 1194 #ifdef BLKGETSIZE64 1195 s >> 20 1167 1196 #else 1168 s >> 20 1169 #endif 1170 ; 1171 } 1172 } 1173 1174 if (outvalB<=0) 1175 { log_msg (1, "Error getting size of %s: %s", drive, strerror (errno)); } 1197 s >> 11 1198 #endif 1199 #else 1200 s >> 20 1201 #endif 1202 ; 1203 } 1204 } 1205 1206 if (outvalB <= 0) { 1207 log_msg(1, "Error getting size of %s: %s", drive, strerror(errno)); 1208 } 1176 1209 #if linux 1177 fileid = open(drive, O_RDONLY);1210 fileid = open(drive, O_RDONLY); 1178 1211 if (fileid) { 1179 if (ioctl 1212 if (ioctl(fileid, HDIO_GETGEO, &hdgeo) != -1) { 1180 1213 if (hdgeo.cylinders && hdgeo.heads && hdgeo.sectors) { 1181 1214 cylindersleft = cylinders = hdgeo.cylinders; 1182 1215 cylindersize = hdgeo.heads * hdgeo.sectors / 2; 1183 1216 outvalA = cylindersize * cylinders / 1024; 1184 log_msg (2, "Got Harddisk geometry, C:%d, H:%d, S:%d", hdgeo.cylinders, hdgeo.heads, hdgeo.sectors); 1217 log_msg(2, "Got Harddisk geometry, C:%d, H:%d, S:%d", 1218 hdgeo.cylinders, hdgeo.heads, hdgeo.sectors); 1185 1219 gotgeo = 1; 1186 1220 } else { 1187 log_msg 1221 log_msg(1, "Harddisk geometry wrong"); 1188 1222 } 1189 1223 } else { 1190 log_msg (1, "Error in ioctl() getting new hard disk geometry (%s), resizing in unsafe mode", strerror(errno)); 1224 log_msg(1, 1225 "Error in ioctl() getting new hard disk geometry (%s), resizing in unsafe mode", 1226 strerror(errno)); 1191 1227 } 1192 1228 close(fileid); 1193 1229 } else { 1194 log_msg (1, "Failed to open %s for reading: %s", drive, strerror(errno)); 1230 log_msg(1, "Failed to open %s for reading: %s", drive, 1231 strerror(errno)); 1195 1232 } 1196 1233 if (!gotgeo) { 1197 log_msg 1234 log_msg(1, "Failed to get harddisk geometry, using old mode"); 1198 1235 } 1199 1236 /* … … 1213 1250 // NEWER DISKS will give sane value for outvalB (close to outvalA, in other words) :) 1214 1251 1215 1216 1252 outvalC = (outvalA > outvalB) ? outvalA : outvalB; 1253 1217 1254 // log_msg (5, "drive = %s, error = %s", drive, strerror (errno)); 1218 1255 // fatal_error ("GPSOD: Unable to get size of drive"); 1219 log_msg(1, "%s --> %ld or %ld --> %ld", drive, outvalA, outvalB, outvalC); 1220 1221 return(outvalC); 1222 } 1223 1256 log_msg(1, "%s --> %ld or %ld --> %ld", drive, outvalA, outvalB, 1257 outvalC); 1258 1259 return (outvalC); 1260 } 1261 1224 1262 /* The old version */ 1225 #if 0 1226 long 1227 get_phys_size_of_drive (char *drive) 1228 { 1229 /*@ pointers *****************************************************/ 1263 #if 0 1264 long get_phys_size_of_drive(char *drive) 1265 { 1266 /*@ pointers **************************************************** */ 1230 1267 #if linux 1231 1232 1233 1234 1235 /*@ buffers ***************************************************** */1236 1237 1238 1239 /*@ long ******************************************************** */1240 1241 1242 1243 1244 1245 #endif 1246 1247 1248 1268 FILE *fin; 1269 char *p; 1270 char *q; 1271 char *r; 1272 /*@ buffers ***************************************************** */ 1273 char *tmp; 1274 char *command; 1275 1276 /*@ long ******************************************************** */ 1277 long outL; 1278 long tempLa; 1279 long tempLb; 1280 long tempLc; 1281 1282 #endif 1283 1284 struct hd_geometry hdgeo; 1285 int fd; 1249 1286 1250 1287 #ifdef __FreeBSD__ 1251 1252 1253 if ((fd = open(drive, O_RDONLY)) != -1) {1254 if (ioctl(fd, DIOCGMEDIASIZE, &o) != -1) {1255 close(fd);1256 1257 1258 close(fd);1259 1260 log_msg (4, "drive = %s, error = %s", drive, strerror(errno));1261 fatal_error("GPSOD: Unable to get size of drive");1288 off_t o; 1289 1290 if ((fd = open(drive, O_RDONLY)) != -1) { 1291 if (ioctl(fd, DIOCGMEDIASIZE, &o) != -1) { 1292 close(fd); 1293 return (long) (o / (off_t) (1024 * 1024)); 1294 } 1295 close(fd); 1296 } 1297 log_msg(4, "drive = %s, error = %s", drive, strerror(errno)); 1298 fatal_error("GPSOD: Unable to get size of drive"); 1262 1299 #else 1263 1300 1264 malloc_string(tmp); 1265 malloc_string(command); 1266 1267 if ((fd = open (drive, O_RDONLY)) != -1) { 1268 if (ioctl (fd, HDIO_GETGEO, &hdgeo) != -1) { 1269 close (fd); 1270 log_msg (2, "Geometry of drive %s is C:%d, H:%d, S%d, its size is %d MB", drive, hdgeo.cylinders, hdgeo.heads, hdgeo.sectors, (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 / 1024)); 1271 if ( hdgeo.cylinders && hdgeo.heads && hdgeo.sectors ) { 1272 return ((long) (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 / 1024)); 1273 } 1274 } 1275 close (fd); 1276 } 1277 1278 assert_string_is_neither_NULL_nor_zerolength(drive); 1279 1280 sprintf (command, 1281 "parted2fdisk -l %s | head -n4 | tr -s '\n' '\t' | tr -s ' ' '\t' | cut -f8,14,16", 1282 drive); 1283 strcpy (tmp, call_program_and_get_last_line_of_output (command)); 1284 if (tmp[0]) 1285 { 1286 p = tmp; 1287 q = strchr (p, ' '); 1288 if (q) 1289 { 1290 *(q++) = '\0'; 1291 r = strchr (q, ' '); 1292 if (r) 1293 { 1294 *(r++) = '\0'; 1295 tempLa = atol (p); 1296 tempLb = atol (q); 1297 tempLc = atol (r); 1298 outL = tempLa * tempLb / 1024 * tempLc / 1024; 1299 if (outL > 100) 1300 { 1301 paranoid_free(tmp); 1302 paranoid_free(command); 1303 return (outL); 1304 } 1305 } 1306 } 1307 } 1308 1309 /* try to grep for 'Drive xxxx: yyy MB' */ 1310 sprintf(command, "parted2fdisk -l %s | grep MB | tr -s ' ' '\t' | cut -f3", drive); 1311 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 1312 if (atol(tmp) > 0) 1313 { 1314 paranoid_free(tmp); 1315 paranoid_free(command); 1316 return (atol(tmp)); 1317 } 1318 1319 /* else, do it the old-fashioned way */ 1320 p = strrchr (drive, (int) '/'); 1321 if (p) 1322 { 1323 strcpy (tmp, p + 1); 1324 } 1325 else 1326 { 1327 paranoid_free(tmp); 1328 paranoid_free(command); 1329 return (-1); 1330 } 1331 sprintf (command, "dmesg | grep %s 2> /dev/null", tmp); 1332 if (!(fin = popen (command, "r"))) 1333 { log_OS_error("Cannot popen dmesg command"); } 1334 else 1335 { 1336 fgets (tmp, MAX_STR_LEN - 1, fin); 1337 while (!feof (fin) && !strstr (tmp, "GB") && !strstr (tmp, "MB")) 1338 { 1339 fgets (tmp, MAX_STR_LEN - 1, fin); 1340 } 1341 if (pclose (fin)) { log_OS_error("Cannot pclose dmesg fin"); } 1342 } 1343 if (!(p = strstr (tmp, "GB")) && !(p = strstr (tmp, "MB"))) 1344 { 1345 log_msg (3, "Cannot find %s's size: dmesg isn't helping either.", 1346 drive); 1347 paranoid_free(tmp); 1348 paranoid_free(command); 1349 return (-1); 1350 } 1351 for (; !isdigit (*(p - 1)); p--); 1352 *p = '\0'; 1353 for (p--; isdigit (*(p - 1)); p--); 1354 outL = atol (p); 1355 if (outL <= 0) 1356 { 1357 paranoid_free(tmp); 1358 paranoid_free(command); 1359 return (-1); 1360 } 1361 if (strstr (tmp, "GB")) 1362 { 1363 outL = outL * 1024; 1364 } 1365 paranoid_free(tmp); 1366 paranoid_free(command); 1367 return (outL * 19 / 20); 1368 #endif 1369 } 1370 #endif /* 0 */ 1301 malloc_string(tmp); 1302 malloc_string(command); 1303 1304 if ((fd = open(drive, O_RDONLY)) != -1) { 1305 if (ioctl(fd, HDIO_GETGEO, &hdgeo) != -1) { 1306 close(fd); 1307 log_msg(2, 1308 "Geometry of drive %s is C:%d, H:%d, S%d, its size is %d MB", 1309 drive, hdgeo.cylinders, hdgeo.heads, hdgeo.sectors, 1310 (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 2 / 1311 1024)); 1312 if (hdgeo.cylinders && hdgeo.heads && hdgeo.sectors) { 1313 return ((long) 1314 (hdgeo.cylinders * hdgeo.heads * hdgeo.sectors / 1315 2 / 1024)); 1316 } 1317 } 1318 close(fd); 1319 } 1320 1321 assert_string_is_neither_NULL_nor_zerolength(drive); 1322 1323 sprintf(command, 1324 "parted2fdisk -l %s | head -n4 | tr -s '\n' '\t' | tr -s ' ' '\t' | cut -f8,14,16", 1325 drive); 1326 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 1327 if (tmp[0]) { 1328 p = tmp; 1329 q = strchr(p, ' '); 1330 if (q) { 1331 *(q++) = '\0'; 1332 r = strchr(q, ' '); 1333 if (r) { 1334 *(r++) = '\0'; 1335 tempLa = atol(p); 1336 tempLb = atol(q); 1337 tempLc = atol(r); 1338 outL = tempLa * tempLb / 1024 * tempLc / 1024; 1339 if (outL > 100) { 1340 paranoid_free(tmp); 1341 paranoid_free(command); 1342 return (outL); 1343 } 1344 } 1345 } 1346 } 1347 1348 /* try to grep for 'Drive xxxx: yyy MB' */ 1349 sprintf(command, 1350 "parted2fdisk -l %s | grep MB | tr -s ' ' '\t' | cut -f3", 1351 drive); 1352 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 1353 if (atol(tmp) > 0) { 1354 paranoid_free(tmp); 1355 paranoid_free(command); 1356 return (atol(tmp)); 1357 } 1358 1359 /* else, do it the old-fashioned way */ 1360 p = strrchr(drive, (int) '/'); 1361 if (p) { 1362 strcpy(tmp, p + 1); 1363 } else { 1364 paranoid_free(tmp); 1365 paranoid_free(command); 1366 return (-1); 1367 } 1368 sprintf(command, "dmesg | grep %s 2> /dev/null", tmp); 1369 if (!(fin = popen(command, "r"))) { 1370 log_OS_error("Cannot popen dmesg command"); 1371 } else { 1372 fgets(tmp, MAX_STR_LEN - 1, fin); 1373 while (!feof(fin) && !strstr(tmp, "GB") && !strstr(tmp, "MB")) { 1374 fgets(tmp, MAX_STR_LEN - 1, fin); 1375 } 1376 if (pclose(fin)) { 1377 log_OS_error("Cannot pclose dmesg fin"); 1378 } 1379 } 1380 if (!(p = strstr(tmp, "GB")) && !(p = strstr(tmp, "MB"))) { 1381 log_msg(3, "Cannot find %s's size: dmesg isn't helping either.", 1382 drive); 1383 paranoid_free(tmp); 1384 paranoid_free(command); 1385 return (-1); 1386 } 1387 for (; !isdigit(*(p - 1)); p--); 1388 *p = '\0'; 1389 for (p--; isdigit(*(p - 1)); p--); 1390 outL = atol(p); 1391 if (outL <= 0) { 1392 paranoid_free(tmp); 1393 paranoid_free(command); 1394 return (-1); 1395 } 1396 if (strstr(tmp, "GB")) { 1397 outL = outL * 1024; 1398 } 1399 paranoid_free(tmp); 1400 paranoid_free(command); 1401 return (outL * 19 / 20); 1402 #endif 1403 } 1404 #endif /* 0 */ 1371 1405 1372 1406 … … 1380 1414 * @return TRUE if the format is supported, FALSE if not. 1381 1415 */ 1382 bool 1383 is_this_a_valid_disk_format (char *format) 1384 { 1385 char *good_formats; 1416 bool is_this_a_valid_disk_format(char *format) 1417 { 1418 char *good_formats; 1386 1419 char *command; 1387 1420 char *format_sz; 1388 1421 1389 1390 1391 1392 1393 1394 1395 1396 1397 sprintf(format_sz, "%s ", format);1422 FILE *pin; 1423 int retval; 1424 malloc_string(good_formats); 1425 malloc_string(command); 1426 malloc_string(format_sz); 1427 1428 assert_string_is_neither_NULL_nor_zerolength(format); 1429 1430 sprintf(format_sz, "%s ", format); 1398 1431 1399 1432 #ifdef __FreeBSD__ 1400 sprintf(command,1401 1433 sprintf(command, 1434 "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '"); 1402 1435 #else 1403 sprintf (command, 1404 "cat /proc/filesystems | grep -v nodev | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '"); 1405 #endif 1406 1407 pin = popen (command, "r"); 1408 if (!pin) 1409 { 1410 log_OS_error ("Unable to read good formats"); 1411 retval=0; 1412 } 1413 else 1414 { 1415 strcpy (good_formats, " "); 1416 (void) fgets (good_formats + 1, MAX_STR_LEN, pin); 1417 if (pclose (pin)) 1418 { log_OS_error("Cannot pclose good formats"); } 1419 strip_spaces (good_formats); 1420 strcat (good_formats, " swap lvm raid ntfs 7 "); // " ntfs 7 " -- um, cheating much? :) 1421 if (strstr (good_formats, format_sz)) 1422 { 1423 retval=1; 1424 } 1425 else 1426 { 1427 retval=0; 1428 } 1429 } 1430 paranoid_free(good_formats); 1431 paranoid_free(command); 1432 paranoid_free(format_sz); 1433 return (retval); 1436 sprintf(command, 1437 "cat /proc/filesystems | grep -v nodev | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '"); 1438 #endif 1439 1440 pin = popen(command, "r"); 1441 if (!pin) { 1442 log_OS_error("Unable to read good formats"); 1443 retval = 0; 1444 } else { 1445 strcpy(good_formats, " "); 1446 (void) fgets(good_formats + 1, MAX_STR_LEN, pin); 1447 if (pclose(pin)) { 1448 log_OS_error("Cannot pclose good formats"); 1449 } 1450 strip_spaces(good_formats); 1451 strcat(good_formats, " swap lvm raid ntfs 7 "); // " ntfs 7 " -- um, cheating much? :) 1452 if (strstr(good_formats, format_sz)) { 1453 retval = 1; 1454 } else { 1455 retval = 0; 1456 } 1457 } 1458 paranoid_free(good_formats); 1459 paranoid_free(command); 1460 paranoid_free(format_sz); 1461 return (retval); 1434 1462 } 1435 1463 … … 1442 1470 * @return TRUE if it's mounted, FALSE if not. 1443 1471 */ 1444 bool is_this_device_mounted 1445 { 1446 1447 /*@ pointers **************************************************** */1448 1449 1450 /*@ buffers ***************************************************** */1451 1452 1453 1454 1455 int retval=0;1456 1472 bool is_this_device_mounted(char *device_raw) 1473 { 1474 1475 /*@ pointers **************************************************** */ 1476 FILE *fin; 1477 1478 /*@ buffers ***************************************************** */ 1479 char *incoming; 1480 char *device_with_tab; 1481 char *device_with_space; 1482 char *tmp; 1483 int retval = 0; 1484 1457 1485 #ifdef __FreeBSD__ 1458 1486 #define SWAPLIST_COMMAND "swapinfo" 1459 1487 #else 1460 1461 #endif 1462 1463 /*@ end vars **************************************************** */1464 1465 1466 1467 1468 1469 assert(device_raw!=NULL);1488 #define SWAPLIST_COMMAND "cat /proc/swaps" 1489 #endif 1490 1491 /*@ end vars **************************************************** */ 1492 1493 malloc_string(incoming); 1494 malloc_string(device_with_tab); 1495 malloc_string(device_with_space); 1496 malloc_string(tmp); 1497 assert(device_raw != NULL); 1470 1498 // assert_string_is_neither_NULL_nor_zerolength(device_raw); 1471 if (device_raw[0] != '/' && !strstr(device_raw, ":/")) 1472 { 1473 log_msg(1, "%s needs to have a '/' prefixed - I'll do it", device_raw); 1474 sprintf(tmp, "/%s", device_raw); 1475 } 1476 else 1477 { 1478 strcpy(tmp, device_raw); 1479 } 1480 log_msg(1, "Is %s mounted?", tmp); 1481 if (!strcmp(tmp, "/proc") || !strcmp(tmp, "proc")) 1482 { 1483 log_msg(1, "I don't know how the heck /proc made it into the mountlist. I'll ignore it."); 1484 return(0); 1485 } 1486 sprintf (device_with_tab, "%s\t", tmp); 1487 sprintf (device_with_space, "%s ", tmp); 1488 1489 if (!(fin = popen ("mount", "r"))) { log_OS_error("Cannot popen 'mount'"); return(FALSE); } 1490 for (fgets (incoming, MAX_STR_LEN - 1, fin); !feof (fin); 1491 fgets (incoming, MAX_STR_LEN - 1, fin)) 1492 { 1493 if ( strstr (incoming, device_with_space) //> incoming 1494 || strstr (incoming, device_with_tab) ) // > incoming) 1495 { 1496 paranoid_pclose (fin); 1497 retval=1; 1498 goto end_of_func; 1499 } 1500 } 1501 paranoid_pclose(fin); 1502 sprintf (tmp, "%s | grep -w \"%s\" > /dev/null 2> /dev/null", 1503 SWAPLIST_COMMAND, device_with_space); 1504 log_msg(4, "tmp (command) = '%s'", tmp); 1505 if (!system (tmp)) 1506 { 1507 retval=1; 1508 goto end_of_func; 1509 } 1510 end_of_func: 1511 paranoid_free(incoming); 1512 paranoid_free(device_with_tab); 1513 paranoid_free(device_with_space); 1514 paranoid_free(tmp); 1515 return (retval); 1499 if (device_raw[0] != '/' && !strstr(device_raw, ":/")) { 1500 log_msg(1, "%s needs to have a '/' prefixed - I'll do it", 1501 device_raw); 1502 sprintf(tmp, "/%s", device_raw); 1503 } else { 1504 strcpy(tmp, device_raw); 1505 } 1506 log_msg(1, "Is %s mounted?", tmp); 1507 if (!strcmp(tmp, "/proc") || !strcmp(tmp, "proc")) { 1508 log_msg(1, 1509 "I don't know how the heck /proc made it into the mountlist. I'll ignore it."); 1510 return (0); 1511 } 1512 sprintf(device_with_tab, "%s\t", tmp); 1513 sprintf(device_with_space, "%s ", tmp); 1514 1515 if (!(fin = popen("mount", "r"))) { 1516 log_OS_error("Cannot popen 'mount'"); 1517 return (FALSE); 1518 } 1519 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); 1520 fgets(incoming, MAX_STR_LEN - 1, fin)) { 1521 if (strstr(incoming, device_with_space) //> incoming 1522 || strstr(incoming, device_with_tab)) // > incoming) 1523 { 1524 paranoid_pclose(fin); 1525 retval = 1; 1526 goto end_of_func; 1527 } 1528 } 1529 paranoid_pclose(fin); 1530 sprintf(tmp, "%s | grep -w \"%s\" > /dev/null 2> /dev/null", 1531 SWAPLIST_COMMAND, device_with_space); 1532 log_msg(4, "tmp (command) = '%s'", tmp); 1533 if (!system(tmp)) { 1534 retval = 1; 1535 goto end_of_func; 1536 } 1537 end_of_func: 1538 paranoid_free(incoming); 1539 paranoid_free(device_with_tab); 1540 paranoid_free(device_with_space); 1541 paranoid_free(tmp); 1542 return (retval); 1516 1543 } 1517 1544 … … 1523 1550 * @return /dev entry for the device, or NULL if it couldn't be allocated. 1524 1551 */ 1525 char * 1526 make_vn (char *fname) 1527 { 1528 char *device = (char*) malloc (MAX_STR_LEN);1529 char *mddevice = (char*) malloc (32);1530 char command[MAX_STR_LEN];1531 int vndev = 2; 1532 if (atoi (call_program_and_get_last_line_of_output ("/sbin/sysctl -n kern.osreldate")) < 1533 1534 1535 sprintf(mddevice, "vn%ic", vndev++);1536 sprintf(command, "vnconfig %s %s", mddevice, fname);1537 1538 1539 1540 1541 while (system(command));1542 1543 sprintf(command, "mdconfig -a -t vnode -f %s", fname);1544 mddevice = call_program_and_get_last_line_of_output(command);1545 if (!strstr(mddevice, "md")) {1546 1547 1548 1549 sprintf(device, "/dev/%s", mddevice);1550 1552 char *make_vn(char *fname) 1553 { 1554 char *device = (char *) malloc(MAX_STR_LEN); 1555 char *mddevice = (char *) malloc(32); 1556 char command[MAX_STR_LEN]; 1557 int vndev = 2; 1558 if (atoi 1559 (call_program_and_get_last_line_of_output 1560 ("/sbin/sysctl -n kern.osreldate")) < 500000) { 1561 do { 1562 sprintf(mddevice, "vn%ic", vndev++); 1563 sprintf(command, "vnconfig %s %s", mddevice, fname); 1564 if (vndev > 10) { 1565 return NULL; 1566 } 1567 } 1568 while (system(command)); 1569 } else { 1570 sprintf(command, "mdconfig -a -t vnode -f %s", fname); 1571 mddevice = call_program_and_get_last_line_of_output(command); 1572 if (!strstr(mddevice, "md")) { 1573 return NULL; 1574 } 1575 } 1576 sprintf(device, "/dev/%s", mddevice); 1577 return device; 1551 1578 } 1552 1579 … … 1561 1588 * @return 0 for success, nonzero for failure. 1562 1589 */ 1563 int 1564 kick_vn (char *dname) 1565 { 1566 char command[MAX_STR_LEN]; 1567 1568 if (strncmp (dname, "/dev/", 5) == 0) { 1569 dname += 5; 1570 } 1571 1572 if (atoi (call_program_and_get_last_line_of_output ("/sbin/sysctl -n kern.osreldate")) < 1573 500000) { 1574 sprintf (command, "vnconfig -d %s", dname); 1575 return system (command); 1576 } else { 1577 sprintf (command, "mdconfig -d -u %s", dname); 1578 return system (command); 1579 } 1580 /*NOTREACHED*/ 1581 return 255; 1590 int kick_vn(char *dname) 1591 { 1592 char command[MAX_STR_LEN]; 1593 1594 if (strncmp(dname, "/dev/", 5) == 0) { 1595 dname += 5; 1596 } 1597 1598 if (atoi 1599 (call_program_and_get_last_line_of_output 1600 ("/sbin/sysctl -n kern.osreldate")) < 500000) { 1601 sprintf(command, "vnconfig -d %s", dname); 1602 return system(command); 1603 } else { 1604 sprintf(command, "mdconfig -d -u %s", dname); 1605 return system(command); 1606 } 1607 /*NOTREACHED*/ return 255; 1582 1608 } 1583 1609 #endif … … 1590 1616 * @return 0 for success, nonzero for failure. 1591 1617 */ 1592 int 1593 mount_CDROM_here (char *device, char *mountpoint) 1594 { 1595 /*@ buffer *******************************************************/ 1596 char *command; 1597 char *dev; 1598 char *options; 1599 int retval; 1600 1601 malloc_string(command); 1602 malloc_string(dev); 1603 malloc_string(options); 1604 assert_string_is_neither_NULL_nor_zerolength(device); 1605 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 1606 1607 make_hole_for_dir(mountpoint); 1608 strcpy(options, "ro"); 1609 if (isdigit(device[0])) 1610 { find_cdrom_device(device, FALSE); } 1611 else 1612 { strcpy(dev, device); } 1613 if (g_ISO_restore_mode) 1614 { 1618 int mount_CDROM_here(char *device, char *mountpoint) 1619 { 1620 /*@ buffer ****************************************************** */ 1621 char *command; 1622 char *dev; 1623 char *options; 1624 int retval; 1625 1626 malloc_string(command); 1627 malloc_string(dev); 1628 malloc_string(options); 1629 assert_string_is_neither_NULL_nor_zerolength(device); 1630 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 1631 1632 make_hole_for_dir(mountpoint); 1633 strcpy(options, "ro"); 1634 if (isdigit(device[0])) { 1635 find_cdrom_device(device, FALSE); 1636 } else { 1637 strcpy(dev, device); 1638 } 1639 if (g_ISO_restore_mode) { 1615 1640 1616 1641 #ifdef __FreeBSD__ 1617 strcpy (dev, make_vn (device)); 1618 if (!dev) { 1619 sprintf (command, "Unable to mount ISO (make_vn(%s) failed)", device); 1620 fatal_error (command); 1621 } 1622 strcpy (device, dev); 1642 strcpy(dev, make_vn(device)); 1643 if (!dev) { 1644 sprintf(command, "Unable to mount ISO (make_vn(%s) failed)", 1645 device); 1646 fatal_error(command); 1647 } 1648 strcpy(device, dev); 1623 1649 #else 1624 strcat(options,",loop"); 1625 #endif 1626 1627 } 1628 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, mountpoint); 1629 /*@ end vars ****************************************************/ 1650 strcat(options, ",loop"); 1651 #endif 1652 1653 } 1654 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, 1655 mountpoint); 1656 /*@ end vars *************************************************** */ 1630 1657 1631 1658 #ifdef __FreeBSD__ 1632 sprintf(command, "mount_cd9660 -r %s %s 2>> %s",1633 1659 sprintf(command, "mount_cd9660 -r %s %s 2>> %s", 1660 device, mountpoint, MONDO_LOGFILE); 1634 1661 1635 1662 #else 1636 sprintf (command, "mount %s -o %s -t iso9660 %s 2>> %s", 1637 device, options, mountpoint, MONDO_LOGFILE); 1638 #endif 1639 1640 log_msg (4, command); 1641 if (strncmp(device, "/dev/", 5) == 0) 1642 { 1643 retract_CD_tray_and_defeat_autorun(); 1644 } 1645 retval = system (command); 1646 log_msg(1, "system(%s) returned %d", command, retval); 1647 1648 paranoid_free(command); 1649 paranoid_free(dev); 1650 paranoid_free(options); 1651 return(retval); 1663 sprintf(command, "mount %s -o %s -t iso9660 %s 2>> %s", 1664 device, options, mountpoint, MONDO_LOGFILE); 1665 #endif 1666 1667 log_msg(4, command); 1668 if (strncmp(device, "/dev/", 5) == 0) { 1669 retract_CD_tray_and_defeat_autorun(); 1670 } 1671 retval = system(command); 1672 log_msg(1, "system(%s) returned %d", command, retval); 1673 1674 paranoid_free(command); 1675 paranoid_free(dev); 1676 paranoid_free(options); 1677 return (retval); 1652 1678 } 1653 1679 … … 1669 1695 */ 1670 1696 void 1671 insist_on_this_cd_number (struct s_bkpinfo*bkpinfo, int cd_number_i_want)1672 { 1673 1674 /*@ int ************************************************************* */1675 1676 1677 1678 /*@ buffers ********************************************************* */1679 1680 1681 1682 assert(bkpinfo!=NULL);1683 1697 insist_on_this_cd_number(struct s_bkpinfo *bkpinfo, int cd_number_i_want) 1698 { 1699 1700 /*@ int ************************************************************* */ 1701 int res = 0; 1702 1703 1704 /*@ buffers ********************************************************* */ 1705 char *tmp; 1706 char *request; 1707 1708 assert(bkpinfo != NULL); 1709 assert(cd_number_i_want > 0); 1684 1710 1685 1711 // log_msg(3, "Insisting on CD number %d", cd_number_i_want); 1686 1712 1687 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) 1688 { 1689 log_msg(3,"No need to insist_on_this_cd_number when the backup type isn't CD-R(W) or NFS or ISO");1690 1691 1692 1693 1694 sprintf(tmp, "mkdir -p "MNT_CDROM);1695 1696 if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == nfs) 1697 1698 1699 1713 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1714 log_msg(3, 1715 "No need to insist_on_this_cd_number when the backup type isn't CD-R(W) or NFS or ISO"); 1716 return; 1717 } 1718 malloc_string(tmp); 1719 malloc_string(request); 1720 sprintf(tmp, "mkdir -p " MNT_CDROM); 1721 run_program_and_log_output(tmp, 5); 1722 if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso 1723 || bkpinfo->backup_media_type == nfs) { 1724 log_msg(3, "Remounting CD"); 1725 g_ISO_restore_mode = TRUE; 1700 1726 // FIXME --- I'm tempted to do something about this... 1701 1727 // Why unmount and remount again and again? 1702 if (is_this_device_mounted(MNT_CDROM)) { run_program_and_log_output("umount "MNT_CDROM, 5); } 1703 system("mkdir -p /tmp/isodir &> /dev/null"); 1704 sprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir, bkpinfo->prefix, cd_number_i_want); 1705 if (!does_file_exist(tmp)) 1706 { 1707 sprintf(tmp, "/tmp/isodir/%s/%s-%d.iso", bkpinfo->nfs_remote_dir, bkpinfo->prefix, cd_number_i_want); 1708 if (does_file_exist(tmp)) 1709 { 1710 log_msg(1, "FIXME - hacking bkpinfo->isodir from '%s' to /tmp/isodir", bkpinfo->isodir); 1711 strcpy(bkpinfo->isodir, "/tmp/isodir"); 1712 } 1713 } 1714 log_msg(3, "Mounting %s at %s", tmp, MNT_CDROM); 1715 if (mount_CDROM_here(tmp, MNT_CDROM)) { fatal_error("Mommy!"); } 1716 // g_current_media_number = cd_number_i_want; 1717 // return; 1718 } 1719 if ((res=what_number_cd_is_this (bkpinfo)) != cd_number_i_want) 1720 { 1721 log_msg(3, "Currently, we hold %d but we want %d", res, cd_number_i_want); 1722 sprintf (tmp, "Insisting on %s #%d", media_descriptor_string(bkpinfo->backup_media_type), cd_number_i_want); 1723 sprintf (request, "Please insert %s #%d and press Enter.", 1724 media_descriptor_string(bkpinfo->backup_media_type), 1725 cd_number_i_want); 1726 log_msg (3, tmp); 1727 while (what_number_cd_is_this (bkpinfo) != cd_number_i_want) 1728 { 1729 paranoid_system ("sync"); 1730 if (is_this_device_mounted (MNT_CDROM)) 1731 { 1732 res = run_program_and_log_output ("umount "MNT_CDROM, FALSE); 1733 } 1734 else 1735 { 1736 res = 0; 1737 } 1738 if (res) 1739 { 1740 log_to_screen ("WARNING - failed to unmount CD-ROM drive"); 1741 } 1742 if (!bkpinfo->please_dont_eject) 1743 { res = eject_device(bkpinfo->media_device); } 1744 else 1745 { res = 0; } 1746 if (res) 1747 { 1748 log_to_screen ("WARNING - failed to eject CD-ROM disk"); 1749 } 1750 popup_and_OK (request); 1751 if (!bkpinfo->please_dont_eject) 1752 { 1753 inject_device(bkpinfo->media_device); 1754 } 1755 paranoid_system ("sync"); 1756 } 1757 log_msg (1, "Thankyou. Proceeding..."); 1758 g_current_media_number = cd_number_i_want; 1759 } 1760 paranoid_free(tmp); 1761 paranoid_free(request); 1728 if (is_this_device_mounted(MNT_CDROM)) { 1729 run_program_and_log_output("umount " MNT_CDROM, 5); 1730 } 1731 system("mkdir -p /tmp/isodir &> /dev/null"); 1732 sprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir, 1733 bkpinfo->nfs_remote_dir, bkpinfo->prefix, 1734 cd_number_i_want); 1735 if (!does_file_exist(tmp)) { 1736 sprintf(tmp, "/tmp/isodir/%s/%s-%d.iso", 1737 bkpinfo->nfs_remote_dir, bkpinfo->prefix, 1738 cd_number_i_want); 1739 if (does_file_exist(tmp)) { 1740 log_msg(1, 1741 "FIXME - hacking bkpinfo->isodir from '%s' to /tmp/isodir", 1742 bkpinfo->isodir); 1743 strcpy(bkpinfo->isodir, "/tmp/isodir"); 1744 } 1745 } 1746 log_msg(3, "Mounting %s at %s", tmp, MNT_CDROM); 1747 if (mount_CDROM_here(tmp, MNT_CDROM)) { 1748 fatal_error("Mommy!"); 1749 } 1750 // g_current_media_number = cd_number_i_want; 1751 // return; 1752 } 1753 if ((res = what_number_cd_is_this(bkpinfo)) != cd_number_i_want) { 1754 log_msg(3, "Currently, we hold %d but we want %d", res, 1755 cd_number_i_want); 1756 sprintf(tmp, "Insisting on %s #%d", 1757 media_descriptor_string(bkpinfo->backup_media_type), 1758 cd_number_i_want); 1759 sprintf(request, "Please insert %s #%d and press Enter.", 1760 media_descriptor_string(bkpinfo->backup_media_type), 1761 cd_number_i_want); 1762 log_msg(3, tmp); 1763 while (what_number_cd_is_this(bkpinfo) != cd_number_i_want) { 1764 paranoid_system("sync"); 1765 if (is_this_device_mounted(MNT_CDROM)) { 1766 res = 1767 run_program_and_log_output("umount " MNT_CDROM, FALSE); 1768 } else { 1769 res = 0; 1770 } 1771 if (res) { 1772 log_to_screen("WARNING - failed to unmount CD-ROM drive"); 1773 } 1774 if (!bkpinfo->please_dont_eject) { 1775 res = eject_device(bkpinfo->media_device); 1776 } else { 1777 res = 0; 1778 } 1779 if (res) { 1780 log_to_screen("WARNING - failed to eject CD-ROM disk"); 1781 } 1782 popup_and_OK(request); 1783 if (!bkpinfo->please_dont_eject) { 1784 inject_device(bkpinfo->media_device); 1785 } 1786 paranoid_system("sync"); 1787 } 1788 log_msg(1, "Thankyou. Proceeding..."); 1789 g_current_media_number = cd_number_i_want; 1790 } 1791 paranoid_free(tmp); 1792 paranoid_free(request); 1762 1793 } 1763 1794 … … 1778 1809 * @ingroup archiveGroup 1779 1810 */ 1780 int interactively_obtain_media_parameters_from_user(struct s_bkpinfo *bkpinfo, bool archiving_to_media) 1811 int interactively_obtain_media_parameters_from_user(struct s_bkpinfo 1812 *bkpinfo, 1813 bool 1814 archiving_to_media) 1781 1815 // archiving_to_media is TRUE if I'm being called by mondoarchive 1782 1816 // archiving_to_media is FALSE if I'm being called by mondorestore 1783 1817 { 1784 1785 1786 1787 1788 1789 FILE*fin;1790 1791 1792 1793 1794 1795 assert(bkpinfo!=NULL);1796 1797 1818 char *tmp; 1819 char *sz_size; 1820 char *command; 1821 char *comment; 1822 int i; 1823 FILE *fin; 1824 1825 malloc_string(tmp); 1826 malloc_string(sz_size); 1827 malloc_string(command); 1828 malloc_string(comment); 1829 assert(bkpinfo != NULL); 1830 sz_size[0] = '\0'; 1831 bkpinfo->nonbootable_backup = FALSE; 1798 1832 1799 1833 // Tape, CD, NFS, ...? 1800 srandom(getpid()); 1801 bkpinfo->backup_media_type = (g_restoring_live_from_cd) ? cdr : which_backup_media_type(bkpinfo->restore_data); 1802 if (bkpinfo->backup_media_type == none) 1803 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 1804 if (bkpinfo->backup_media_type == tape && bkpinfo->restore_data) 1805 { popup_and_OK("Please remove CD/floppy from drive(s)"); } 1806 log_msg(3, "media type = %s", bkptype_to_string(bkpinfo->backup_media_type)); 1807 if (archiving_to_media) 1808 { 1809 sensibly_set_tmpdir_and_scratchdir(bkpinfo); 1810 } 1811 bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4; 1812 bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1:5; 1813 bkpinfo->use_lzo = (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE; 1834 srandom(getpid()); 1835 bkpinfo->backup_media_type = 1836 (g_restoring_live_from_cd) ? cdr : 1837 which_backup_media_type(bkpinfo->restore_data); 1838 if (bkpinfo->backup_media_type == none) { 1839 log_to_screen("User has chosen not to backup the PC"); 1840 finish(1); 1841 } 1842 if (bkpinfo->backup_media_type == tape && bkpinfo->restore_data) { 1843 popup_and_OK("Please remove CD/floppy from drive(s)"); 1844 } 1845 log_msg(3, "media type = %s", 1846 bkptype_to_string(bkpinfo->backup_media_type)); 1847 if (archiving_to_media) { 1848 sensibly_set_tmpdir_and_scratchdir(bkpinfo); 1849 } 1850 bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4; 1851 bkpinfo->compression_level = 1852 (bkpinfo->backup_media_type == cdstream) ? 1 : 5; 1853 bkpinfo->use_lzo = 1854 (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE; 1814 1855 1815 1856 /* … … 1826 1867 */ 1827 1868 1828 1869 mvaddstr_and_log_it(2, 0, " "); 1829 1870 1830 1871 // Find device's /dev (or SCSI) entry 1831 switch(bkpinfo->backup_media_type) 1832 { 1833 case cdr: 1834 case cdrw: 1835 case dvd: 1836 if (archiving_to_media) 1837 { 1838 if (ask_me_yes_or_no("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) 1839 { bkpinfo->manual_cd_tray = TRUE; } 1840 if ((bkpinfo->compression_level = which_compression_level()) == -1) 1841 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 1842 sprintf(comment, "What speed is your %s (re)writer?", media_descriptor_string(bkpinfo->backup_media_type)); 1843 if (bkpinfo->backup_media_type==dvd) 1844 { 1845 find_dvd_device(bkpinfo->media_device, FALSE); 1846 strcpy(tmp, "1"); 1847 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 1848 log_msg(1, "Setting to DVD defaults"); 1849 } 1850 else 1851 { 1852 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM); 1853 strcpy(tmp, "4"); 1854 strcpy(sz_size, "650"); 1855 log_msg(1, "Setting to CD defaults"); 1856 } 1857 if (bkpinfo->backup_media_type != dvd) 1858 { 1859 if (!popup_and_get_string("Speed", comment, tmp, 4)) 1860 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 1861 } 1862 bkpinfo->cdrw_speed = atoi(tmp); // if DVD then this shouldn't ever be used anyway :) 1863 sprintf(comment, "How much data (in Megabytes) will each %s store?", media_descriptor_string(bkpinfo->backup_media_type)); 1864 if (!popup_and_get_string("Size", comment, sz_size, 5)) 1865 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 1866 for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = atoi(sz_size); } 1867 if (bkpinfo->media_size[0] <=0) 1868 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 1869 } 1870 case cdstream: 1871 if (bkpinfo->disaster_recovery) 1872 { 1873 strcpy(bkpinfo->media_device, "/dev/cdrom"); 1874 log_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device); 1875 } 1876 else if (bkpinfo->restore_data 1877 || bkpinfo->backup_media_type == dvd) 1878 { 1879 if (!bkpinfo->media_device[0]) 1880 { strcpy(bkpinfo->media_device, "/dev/cdrom"); } // just for the heck of it :) 1881 log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device); 1882 if (bkpinfo->backup_media_type == dvd || find_cdrom_device (bkpinfo->media_device, FALSE)) 1883 { 1884 log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device); 1885 sprintf(comment, "Please specify your %s drive's /dev entry", media_descriptor_string(bkpinfo->backup_media_type)); 1886 if (!popup_and_get_string("Device?", comment, bkpinfo->media_device, MAX_STR_LEN/4)) 1887 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 1888 } 1889 log_msg(2, "%s device found at %s", media_descriptor_string(bkpinfo->backup_media_type), bkpinfo->media_device); 1890 } 1891 else 1892 { 1893 if (find_cdrw_device(bkpinfo->media_device)) { bkpinfo->media_device[0]='\0'; } 1894 if (bkpinfo->media_device[0]) 1895 { 1896 sprintf(tmp, "I think I've found your %s burner at SCSI node %s; am I right on the money?", media_descriptor_string(bkpinfo->backup_media_type), bkpinfo->media_device); 1897 if (!ask_me_yes_or_no(tmp)) { bkpinfo->media_device[0]='\0'; } 1898 } 1899 if (!bkpinfo->media_device[0]) 1900 { 1901 if (g_kernel_version < 2.6) 1902 { 1903 i=popup_and_get_string("Device node?", "What is the SCSI node of your CD (re)writer, please?", bkpinfo->media_device, MAX_STR_LEN/4); 1904 } 1905 else 1906 { 1907 i=popup_and_get_string("/dev entry?", "What is the /dev entry of your CD (re)writer, please?", bkpinfo->media_device, MAX_STR_LEN/4); 1908 } 1909 if (!i) 1910 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 1911 } 1912 } 1913 if (bkpinfo->backup_media_type == cdstream) 1914 { 1915 for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = 650; } 1916 } 1917 break; 1918 case udev: 1919 if (!ask_me_yes_or_no("This option is for advanced users only. Are you sure?")) 1920 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 1921 case tape: 1922 1923 if (find_tape_device_and_size(bkpinfo->media_device, sz_size)) 1924 { 1925 log_msg(3, "Ok, using vanilla scsi tape."); 1926 strcpy(bkpinfo->media_device, VANILLA_SCSI_TAPE); 1927 if ((fin=fopen(bkpinfo->media_device, "r"))) 1928 { paranoid_fclose(fin); } 1929 else 1930 { strcpy(bkpinfo->media_device, "/dev/osst0"); } 1931 } 1932 if (bkpinfo->media_device[0]) 1933 { 1934 if ((fin=fopen(bkpinfo->media_device, "r"))) 1935 { paranoid_fclose(fin); } 1936 else 1937 { 1938 if (does_file_exist("/tmp/mondo-restore.cfg")) 1939 { 1940 read_cfg_var("/tmp/mondo-restore.cfg", "media-dev", bkpinfo->media_device); 1941 } 1942 } 1943 sprintf(tmp, "I think I've found your tape streamer at %s; am I right on the money?", bkpinfo->media_device); 1944 } 1945 if (bkpinfo->media_device[0]) 1946 { 1947 sprintf(tmp, "I think I've found your tape streamer at %s; am I right on the money?", bkpinfo->media_device); 1948 if (!ask_me_yes_or_no(tmp)) { bkpinfo->media_device[0]='\0'; } 1949 } 1950 if (!bkpinfo->media_device[0]) 1951 { 1952 if (!popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", bkpinfo->media_device, MAX_STR_LEN/4)) 1953 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 1954 } 1955 sprintf(tmp, "ls -l %s", bkpinfo->media_device); 1956 if (run_program_and_log_output(tmp, FALSE)) 1957 { log_to_screen("User has not specified a valid /dev entry"); finish(1); } 1958 log_msg(4, "sz_size = %s", sz_size); 1959 sz_size[0] = '\0'; 1872 switch (bkpinfo->backup_media_type) { 1873 case cdr: 1874 case cdrw: 1875 case dvd: 1876 if (archiving_to_media) { 1877 if (ask_me_yes_or_no 1878 ("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) 1879 { 1880 bkpinfo->manual_cd_tray = TRUE; 1881 } 1882 if ((bkpinfo->compression_level = 1883 which_compression_level()) == -1) { 1884 log_to_screen("User has chosen not to backup the PC"); 1885 finish(1); 1886 } 1887 sprintf(comment, "What speed is your %s (re)writer?", 1888 media_descriptor_string(bkpinfo->backup_media_type)); 1889 if (bkpinfo->backup_media_type == dvd) { 1890 find_dvd_device(bkpinfo->media_device, FALSE); 1891 strcpy(tmp, "1"); 1892 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 1893 log_msg(1, "Setting to DVD defaults"); 1894 } else { 1895 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM); 1896 strcpy(tmp, "4"); 1897 strcpy(sz_size, "650"); 1898 log_msg(1, "Setting to CD defaults"); 1899 } 1900 if (bkpinfo->backup_media_type != dvd) { 1901 if (!popup_and_get_string("Speed", comment, tmp, 4)) { 1902 log_to_screen("User has chosen not to backup the PC"); 1903 finish(1); 1904 } 1905 } 1906 bkpinfo->cdrw_speed = atoi(tmp); // if DVD then this shouldn't ever be used anyway :) 1907 sprintf(comment, 1908 "How much data (in Megabytes) will each %s store?", 1909 media_descriptor_string(bkpinfo->backup_media_type)); 1910 if (!popup_and_get_string("Size", comment, sz_size, 5)) { 1911 log_to_screen("User has chosen not to backup the PC"); 1912 finish(1); 1913 } 1914 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 1915 bkpinfo->media_size[i] = atoi(sz_size); 1916 } 1917 if (bkpinfo->media_size[0] <= 0) { 1918 log_to_screen("User has chosen not to backup the PC"); 1919 finish(1); 1920 } 1921 } 1922 case cdstream: 1923 if (bkpinfo->disaster_recovery) { 1924 strcpy(bkpinfo->media_device, "/dev/cdrom"); 1925 log_msg(2, "CD-ROM device assumed to be at %s", 1926 bkpinfo->media_device); 1927 } else if (bkpinfo->restore_data 1928 || bkpinfo->backup_media_type == dvd) { 1929 if (!bkpinfo->media_device[0]) { 1930 strcpy(bkpinfo->media_device, "/dev/cdrom"); 1931 } // just for the heck of it :) 1932 log_msg(1, "bkpinfo->media_device = %s", 1933 bkpinfo->media_device); 1934 if (bkpinfo->backup_media_type == dvd 1935 || find_cdrom_device(bkpinfo->media_device, FALSE)) { 1936 log_msg(1, "bkpinfo->media_device = %s", 1937 bkpinfo->media_device); 1938 sprintf(comment, 1939 "Please specify your %s drive's /dev entry", 1940 media_descriptor_string(bkpinfo-> 1941 backup_media_type)); 1942 if (!popup_and_get_string 1943 ("Device?", comment, bkpinfo->media_device, 1944 MAX_STR_LEN / 4)) { 1945 log_to_screen("User has chosen not to backup the PC"); 1946 finish(1); 1947 } 1948 } 1949 log_msg(2, "%s device found at %s", 1950 media_descriptor_string(bkpinfo->backup_media_type), 1951 bkpinfo->media_device); 1952 } else { 1953 if (find_cdrw_device(bkpinfo->media_device)) { 1954 bkpinfo->media_device[0] = '\0'; 1955 } 1956 if (bkpinfo->media_device[0]) { 1957 sprintf(tmp, 1958 "I think I've found your %s burner at SCSI node %s; am I right on the money?", 1959 media_descriptor_string(bkpinfo-> 1960 backup_media_type), 1961 bkpinfo->media_device); 1962 if (!ask_me_yes_or_no(tmp)) { 1963 bkpinfo->media_device[0] = '\0'; 1964 } 1965 } 1966 if (!bkpinfo->media_device[0]) { 1967 if (g_kernel_version < 2.6) { 1968 i = popup_and_get_string("Device node?", 1969 "What is the SCSI node of your CD (re)writer, please?", 1970 bkpinfo->media_device, 1971 MAX_STR_LEN / 4); 1972 } else { 1973 i = popup_and_get_string("/dev entry?", 1974 "What is the /dev entry of your CD (re)writer, please?", 1975 bkpinfo->media_device, 1976 MAX_STR_LEN / 4); 1977 } 1978 if (!i) { 1979 log_to_screen("User has chosen not to backup the PC"); 1980 finish(1); 1981 } 1982 } 1983 } 1984 if (bkpinfo->backup_media_type == cdstream) { 1985 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 1986 bkpinfo->media_size[i] = 650; 1987 } 1988 } 1989 break; 1990 case udev: 1991 if (!ask_me_yes_or_no 1992 ("This option is for advanced users only. Are you sure?")) { 1993 log_to_screen("User has chosen not to backup the PC"); 1994 finish(1); 1995 } 1996 case tape: 1997 1998 if (find_tape_device_and_size(bkpinfo->media_device, sz_size)) { 1999 log_msg(3, "Ok, using vanilla scsi tape."); 2000 strcpy(bkpinfo->media_device, VANILLA_SCSI_TAPE); 2001 if ((fin = fopen(bkpinfo->media_device, "r"))) { 2002 paranoid_fclose(fin); 2003 } else { 2004 strcpy(bkpinfo->media_device, "/dev/osst0"); 2005 } 2006 } 2007 if (bkpinfo->media_device[0]) { 2008 if ((fin = fopen(bkpinfo->media_device, "r"))) { 2009 paranoid_fclose(fin); 2010 } else { 2011 if (does_file_exist("/tmp/mondo-restore.cfg")) { 2012 read_cfg_var("/tmp/mondo-restore.cfg", "media-dev", 2013 bkpinfo->media_device); 2014 } 2015 } 2016 sprintf(tmp, 2017 "I think I've found your tape streamer at %s; am I right on the money?", 2018 bkpinfo->media_device); 2019 } 2020 if (bkpinfo->media_device[0]) { 2021 sprintf(tmp, 2022 "I think I've found your tape streamer at %s; am I right on the money?", 2023 bkpinfo->media_device); 2024 if (!ask_me_yes_or_no(tmp)) { 2025 bkpinfo->media_device[0] = '\0'; 2026 } 2027 } 2028 if (!bkpinfo->media_device[0]) { 2029 if (!popup_and_get_string 2030 ("Device name?", 2031 "What is the /dev entry of your tape streamer?", 2032 bkpinfo->media_device, MAX_STR_LEN / 4)) { 2033 log_to_screen("User has chosen not to backup the PC"); 2034 finish(1); 2035 } 2036 } 2037 sprintf(tmp, "ls -l %s", bkpinfo->media_device); 2038 if (run_program_and_log_output(tmp, FALSE)) { 2039 log_to_screen("User has not specified a valid /dev entry"); 2040 finish(1); 2041 } 2042 log_msg(4, "sz_size = %s", sz_size); 2043 sz_size[0] = '\0'; 1960 2044 /* 1961 2045 if ((size_sz[0]=='\0' || atol(size_sz)==0) && archiving_to_media) … … 1965 2049 } 1966 2050 */ 1967 if (sz_size[0]=='\0') 1968 { bkpinfo->media_size[0] = 0; } 1969 else 1970 { bkpinfo->media_size[0] = friendly_sizestr_to_sizelong (sz_size)/2 - 50; } 1971 log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]); 1972 if (bkpinfo->media_size[0] <= 0) { bkpinfo->media_size[0] = 0; } 1973 for(i=1; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = bkpinfo->media_size[0]; } 1974 if (archiving_to_media) 1975 { 1976 if ((bkpinfo->compression_level = which_compression_level()) == -1) 1977 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 1978 } 1979 break; 1980 1981 1982 1983 case nfs: 1984 if (!bkpinfo->nfs_mount[0]) { strcpy(bkpinfo->nfs_mount, call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1")); } 2051 if (sz_size[0] == '\0') { 2052 bkpinfo->media_size[0] = 0; 2053 } else { 2054 bkpinfo->media_size[0] = 2055 friendly_sizestr_to_sizelong(sz_size) / 2 - 50; 2056 } 2057 log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]); 2058 if (bkpinfo->media_size[0] <= 0) { 2059 bkpinfo->media_size[0] = 0; 2060 } 2061 for (i = 1; i <= MAX_NOOF_MEDIA; i++) { 2062 bkpinfo->media_size[i] = bkpinfo->media_size[0]; 2063 } 2064 if (archiving_to_media) { 2065 if ((bkpinfo->compression_level = 2066 which_compression_level()) == -1) { 2067 log_to_screen("User has chosen not to backup the PC"); 2068 finish(1); 2069 } 2070 } 2071 break; 2072 2073 2074 2075 case nfs: 2076 if (!bkpinfo->nfs_mount[0]) { 2077 strcpy(bkpinfo->nfs_mount, 2078 call_program_and_get_last_line_of_output 2079 ("mount | grep \":\" | cut -d' ' -f1 | head -n1")); 2080 } 1985 2081 #ifdef __FreeBSD__ 1986 2082 if (TRUE) 1987 2083 #else 1988 if (!bkpinfo->disaster_recovery ) 1989 #endif 1990 { 1991 if (!popup_and_get_string("NFS dir.", "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)", bkpinfo->nfs_mount, MAX_STR_LEN/4)) 1992 { 1993 log_to_screen("User has chosen not to backup the PC"); 1994 finish(1); 1995 } 1996 if (!bkpinfo->restore_data) 1997 { 1998 if ((bkpinfo->compression_level = which_compression_level()) == -1) 1999 { 2000 log_to_screen("User has chosen not to backup the PC"); 2001 finish(1); 2002 } 2003 } 2004 sprintf(command, "mount | grep %s | cut -d' ' -f3", bkpinfo->nfs_mount); 2005 strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(command)); 2006 } 2007 if (bkpinfo->disaster_recovery) 2008 { 2009 system("umount /tmp/isodir 2> /dev/null"); 2010 if (!popup_and_get_string("NFS share", "Which remote NFS share should I mount?", bkpinfo->nfs_mount, MAX_STR_LEN)) 2011 { 2012 log_to_screen("User has chosen not to backup the PC"); 2013 finish(1); 2014 } 2015 } 2016 if (!is_this_device_mounted(bkpinfo->nfs_mount)) 2017 { 2018 sprintf(bkpinfo->isodir, "/tmp/isodir"); 2019 run_program_and_log_output("mkdir -p /tmp/isodir", 5); 2020 sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir", bkpinfo->nfs_mount); 2021 run_program_and_log_output(tmp, 5); 2022 } 2023 if (!is_this_device_mounted(bkpinfo->nfs_mount)) 2024 { 2025 popup_and_OK("Please mount that partition before you try to backup to or restore from it."); 2026 finish(1); 2027 } 2028 strcpy(tmp, bkpinfo->nfs_remote_dir); 2029 if (!popup_and_get_string("Directory", "Which directory within that mountpoint?", tmp, MAX_STR_LEN)) 2030 { 2031 log_to_screen("User has chosen not to backup the PC"); 2032 finish(1); 2033 } 2034 strcpy(bkpinfo->nfs_remote_dir, tmp); 2035 for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = 650; } 2036 log_msg(3, "Just set nfs_remote_dir to %s", bkpinfo->nfs_remote_dir); 2037 log_msg(3, "isodir is still %s", bkpinfo->isodir); 2038 break; 2039 2040 case iso: 2041 if (!bkpinfo->disaster_recovery) 2042 { 2043 if (!popup_and_get_string("Storage dir.", "Please enter the full path that contains your ISO images. Example: /mnt/raid0_0", bkpinfo->isodir, MAX_STR_LEN/4)) 2044 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 2045 if (archiving_to_media) { 2046 if ((bkpinfo->compression_level = which_compression_level()) == -1) 2047 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 2048 if (!popup_and_get_string ("ISO size.", "Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s you plan to backup to.", sz_size, 16)) 2049 { log_to_screen ("User has chosen not to backup the PC"); finish(1); } 2050 for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = atoi (sz_size); } 2051 if (!popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix, MAX_STR_LEN/4)) 2052 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 2053 } else { 2054 for (i=0;i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = 650;} 2055 } 2056 } 2057 break; 2058 default: 2059 fatal_error("I, Mojo Jojo, shall defeat those pesky Powerpuff Girls!"); 2060 } 2061 2062 if (archiving_to_media) 2063 { 2084 if (!bkpinfo->disaster_recovery) 2085 #endif 2086 { 2087 if (!popup_and_get_string 2088 ("NFS dir.", 2089 "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)", 2090 bkpinfo->nfs_mount, MAX_STR_LEN / 4)) { 2091 log_to_screen("User has chosen not to backup the PC"); 2092 finish(1); 2093 } 2094 if (!bkpinfo->restore_data) { 2095 if ((bkpinfo->compression_level = 2096 which_compression_level()) == -1) { 2097 log_to_screen("User has chosen not to backup the PC"); 2098 finish(1); 2099 } 2100 } 2101 sprintf(command, "mount | grep %s | cut -d' ' -f3", 2102 bkpinfo->nfs_mount); 2103 strcpy(bkpinfo->isodir, 2104 call_program_and_get_last_line_of_output(command)); 2105 } 2106 if (bkpinfo->disaster_recovery) { 2107 system("umount /tmp/isodir 2> /dev/null"); 2108 if (!popup_and_get_string 2109 ("NFS share", "Which remote NFS share should I mount?", 2110 bkpinfo->nfs_mount, MAX_STR_LEN)) { 2111 log_to_screen("User has chosen not to backup the PC"); 2112 finish(1); 2113 } 2114 } 2115 if (!is_this_device_mounted(bkpinfo->nfs_mount)) { 2116 sprintf(bkpinfo->isodir, "/tmp/isodir"); 2117 run_program_and_log_output("mkdir -p /tmp/isodir", 5); 2118 sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir", 2119 bkpinfo->nfs_mount); 2120 run_program_and_log_output(tmp, 5); 2121 } 2122 if (!is_this_device_mounted(bkpinfo->nfs_mount)) { 2123 popup_and_OK 2124 ("Please mount that partition before you try to backup to or restore from it."); 2125 finish(1); 2126 } 2127 strcpy(tmp, bkpinfo->nfs_remote_dir); 2128 if (!popup_and_get_string 2129 ("Directory", "Which directory within that mountpoint?", tmp, 2130 MAX_STR_LEN)) { 2131 log_to_screen("User has chosen not to backup the PC"); 2132 finish(1); 2133 } 2134 strcpy(bkpinfo->nfs_remote_dir, tmp); 2135 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 2136 bkpinfo->media_size[i] = 650; 2137 } 2138 log_msg(3, "Just set nfs_remote_dir to %s", 2139 bkpinfo->nfs_remote_dir); 2140 log_msg(3, "isodir is still %s", bkpinfo->isodir); 2141 break; 2142 2143 case iso: 2144 if (!bkpinfo->disaster_recovery) { 2145 if (!popup_and_get_string 2146 ("Storage dir.", 2147 "Please enter the full path that contains your ISO images. Example: /mnt/raid0_0", 2148 bkpinfo->isodir, MAX_STR_LEN / 4)) { 2149 log_to_screen("User has chosen not to backup the PC"); 2150 finish(1); 2151 } 2152 if (archiving_to_media) { 2153 if ((bkpinfo->compression_level = 2154 which_compression_level()) == -1) { 2155 log_to_screen("User has chosen not to backup the PC"); 2156 finish(1); 2157 } 2158 if (!popup_and_get_string 2159 ("ISO size.", 2160 "Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s you plan to backup to.", 2161 sz_size, 16)) { 2162 log_to_screen("User has chosen not to backup the PC"); 2163 finish(1); 2164 } 2165 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 2166 bkpinfo->media_size[i] = atoi(sz_size); 2167 } 2168 if (!popup_and_get_string 2169 ("Prefix.", 2170 "Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files", 2171 bkpinfo->prefix, MAX_STR_LEN / 4)) { 2172 log_to_screen("User has chosen not to backup the PC"); 2173 finish(1); 2174 } 2175 } else { 2176 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 2177 bkpinfo->media_size[i] = 650; 2178 } 2179 } 2180 } 2181 break; 2182 default: 2183 fatal_error 2184 ("I, Mojo Jojo, shall defeat those pesky Powerpuff Girls!"); 2185 } 2186 2187 if (archiving_to_media) { 2064 2188 2065 2189 #ifdef __FreeBSD__ 2066 strcpy (bkpinfo->boot_device, call_program_and_get_last_line_of_output 2067 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'")); 2190 strcpy(bkpinfo->boot_device, 2191 call_program_and_get_last_line_of_output 2192 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'")); 2068 2193 #else 2069 strcpy (bkpinfo->boot_device, call_program_and_get_last_line_of_output 2070 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'")); 2071 #endif 2072 i = which_boot_loader(bkpinfo->boot_device); 2073 if (i=='U') // unknown 2074 { 2194 strcpy(bkpinfo->boot_device, 2195 call_program_and_get_last_line_of_output 2196 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'")); 2197 #endif 2198 i = which_boot_loader(bkpinfo->boot_device); 2199 if (i == 'U') // unknown 2200 { 2075 2201 2076 2202 #ifdef __FreeBSD__ 2077 if (!popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/ad0)", bkpinfo->boot_device, MAX_STR_LEN/4)) 2078 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 2079 i = which_boot_loader (bkpinfo->boot_device); 2203 if (!popup_and_get_string 2204 ("Boot device", 2205 "What is your boot device? (e.g. /dev/ad0)", 2206 bkpinfo->boot_device, MAX_STR_LEN / 4)) { 2207 log_to_screen("User has chosen not to backup the PC"); 2208 finish(1); 2209 } 2210 i = which_boot_loader(bkpinfo->boot_device); 2080 2211 #else 2081 if (!popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/hda)", bkpinfo->boot_device, MAX_STR_LEN/4)) 2082 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 2083 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) { i='L'; } 2084 else if (does_string_exist_in_boot_block(bkpinfo->boot_device, "ELILO")) { i='E'; } 2085 else if (does_string_exist_in_boot_block(bkpinfo->boot_device, "GRUB")) { i='G'; } 2086 else { i = 'U'; } 2087 #endif 2088 if (i == 'U') 2089 { 2090 if (ask_me_yes_or_no("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?")) 2212 if (!popup_and_get_string 2213 ("Boot device", 2214 "What is your boot device? (e.g. /dev/hda)", 2215 bkpinfo->boot_device, MAX_STR_LEN / 4)) { 2216 log_to_screen("User has chosen not to backup the PC"); 2217 finish(1); 2218 } 2219 if (does_string_exist_in_boot_block 2220 (bkpinfo->boot_device, "LILO")) { 2221 i = 'L'; 2222 } else 2223 if (does_string_exist_in_boot_block 2224 (bkpinfo->boot_device, "ELILO")) { 2225 i = 'E'; 2226 } else 2227 if (does_string_exist_in_boot_block 2228 (bkpinfo->boot_device, "GRUB")) { 2229 i = 'G'; 2230 } else { 2231 i = 'U'; 2232 } 2233 #endif 2234 if (i == 'U') { 2235 if (ask_me_yes_or_no 2236 ("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?")) 2237 { 2238 i = 'R'; // raw 2239 } else { 2240 log_to_screen 2241 ("I cannot find your boot loader. Please run mondoarchive with parameters."); 2242 finish(1); 2243 } 2244 } 2245 } 2246 bkpinfo->boot_loader = i; 2247 strcpy(bkpinfo->include_paths, "/"); 2248 if (!popup_and_get_string 2249 ("Backup paths", 2250 "Please enter paths which you want me to backup. The default is '/' (i.e. everything).", 2251 bkpinfo->include_paths, MAX_STR_LEN)) { 2252 log_to_screen("User has chosen not to backup the PC"); 2253 finish(1); 2254 } 2255 strcpy(tmp, list_of_NFS_mounts_only()); 2256 if (strlen(tmp) > 2) { 2257 if (bkpinfo->exclude_paths[0]) { 2258 strcat(bkpinfo->exclude_paths, " "); 2259 } 2260 strncpy(bkpinfo->exclude_paths, tmp, MAX_STR_LEN); 2261 } 2262 // NTFS 2263 strcpy(tmp, 2264 call_program_and_get_last_line_of_output 2265 ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'")); 2266 if (strlen(tmp) > 2) { 2267 if (!popup_and_get_string 2268 ("NTFS partitions", 2269 "Please enter/confirm the NTFS partitions you wish to backup as well.", 2270 tmp, MAX_STR_LEN / 4)) { 2271 log_to_screen("User has chosen not to backup the PC"); 2272 finish(1); 2273 } 2274 strncpy(bkpinfo->image_devs, tmp, MAX_STR_LEN / 4); 2275 } 2276 2277 2278 if (!popup_and_get_string 2279 ("Exclude paths", 2280 "Please enter paths which you do NOT want to backup. Separate them with spaces. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup.", 2281 bkpinfo->exclude_paths, MAX_STR_LEN)) { 2282 log_to_screen("User has chosen not to backup the PC"); 2283 finish(1); 2284 } 2285 bkpinfo->make_cd_use_lilo = FALSE; 2286 bkpinfo->backup_data = TRUE; 2287 bkpinfo->verify_data = 2288 ask_me_yes_or_no 2289 ("Will you want to verify your backups after Mondo has created them?"); 2290 2291 #ifndef __FreeBSD__ 2292 if (!ask_me_yes_or_no 2293 ("Are you confident that your kernel is a sane, sensible, standard Linux kernel? Say 'no' if you are using a Gentoo <1.4 or Debian <3.0, please.")) 2294 #endif 2091 2295 { 2092 i = 'R'; // raw 2093 } 2094 else 2095 { 2096 log_to_screen("I cannot find your boot loader. Please run mondoarchive with parameters."); finish(1); 2097 } 2098 } 2099 } 2100 bkpinfo->boot_loader = i; 2101 strcpy(bkpinfo->include_paths, "/"); 2102 if (!popup_and_get_string("Backup paths", "Please enter paths which you want me to backup. The default is '/' (i.e. everything).", bkpinfo->include_paths, MAX_STR_LEN)) 2103 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 2104 strcpy(tmp, list_of_NFS_mounts_only()); 2105 if (strlen(tmp)>2) 2106 { 2107 if (bkpinfo->exclude_paths[0]) { strcat(bkpinfo->exclude_paths, " "); } 2108 strncpy(bkpinfo->exclude_paths, tmp, MAX_STR_LEN); 2109 } 2110 2111 // NTFS 2112 strcpy(tmp, call_program_and_get_last_line_of_output("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'")); 2113 if (strlen(tmp) > 2) 2114 { 2115 if (!popup_and_get_string("NTFS partitions", "Please enter/confirm the NTFS partitions you wish to backup as well.", tmp, MAX_STR_LEN/4)) 2116 { log_to_screen ("User has chosen not to backup the PC"); finish(1); } 2117 strncpy (bkpinfo->image_devs, tmp, MAX_STR_LEN/4); 2118 } 2119 2120 2121 if (!popup_and_get_string("Exclude paths", "Please enter paths which you do NOT want to backup. Separate them with spaces. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup.", bkpinfo->exclude_paths, MAX_STR_LEN)) 2122 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 2123 bkpinfo->make_cd_use_lilo = FALSE; 2124 bkpinfo->backup_data = TRUE; 2125 bkpinfo->verify_data = ask_me_yes_or_no("Will you want to verify your backups after Mondo has created them?"); 2126 2127 #ifndef __FreeBSD__ 2128 if (!ask_me_yes_or_no("Are you confident that your kernel is a sane, sensible, standard Linux kernel? Say 'no' if you are using a Gentoo <1.4 or Debian <3.0, please.")) 2129 #endif 2130 { strcpy(bkpinfo->kernel_path, "FAILSAFE"); } 2131 2132 if (!ask_me_yes_or_no("Are you sure you want to proceed? Hit 'no' to abort.")) 2133 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 2134 } 2135 else 2136 { 2137 bkpinfo->restore_data = TRUE; // probably... 2138 } 2139 2140 if (bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == nfs) 2141 { 2142 g_ISO_restore_mode = TRUE; 2143 } 2144 2296 strcpy(bkpinfo->kernel_path, "FAILSAFE"); 2297 } 2298 2299 if (!ask_me_yes_or_no 2300 ("Are you sure you want to proceed? Hit 'no' to abort.")) { 2301 log_to_screen("User has chosen not to backup the PC"); 2302 finish(1); 2303 } 2304 } else { 2305 bkpinfo->restore_data = TRUE; // probably... 2306 } 2307 2308 if (bkpinfo->backup_media_type == iso 2309 || bkpinfo->backup_media_type == nfs) { 2310 g_ISO_restore_mode = TRUE; 2311 } 2145 2312 #ifdef __FreeSD__ 2146 2313 // skip 2147 2314 #else 2148 if (bkpinfo->backup_media_type == nfs) 2149 { 2150 sprintf(tmp, "mount | grep \"%s\" | cut -d' ' -f3",bkpinfo->nfs_mount);2315 if (bkpinfo->backup_media_type == nfs) { 2316 sprintf(tmp, "mount | grep \"%s\" | cut -d' ' -f3", 2317 bkpinfo->nfs_mount); 2151 2318 // strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(tmp)); 2152 log_msg(3, "I think the NFS mount is mounted at %s", bkpinfo->isodir); 2153 } 2154 log_it("isodir = %s", bkpinfo->isodir); 2155 log_it("nfs_mount = '%s'", bkpinfo->nfs_mount); 2156 #endif 2157 2158 log_it("media device = %s", bkpinfo->media_device); 2159 log_it("media size = %ld", bkpinfo->media_size[1]); 2160 log_it("media type = %s", bkptype_to_string(bkpinfo->backup_media_type)); 2161 log_it("compression = %ld", bkpinfo->compression_level); 2162 log_it("include_paths = '%s'", bkpinfo->include_paths); 2163 log_it("exclude_paths = '%s'", bkpinfo->exclude_paths); 2164 log_it("scratchdir = '%s'", bkpinfo->scratchdir); 2165 log_it("tmpdir = '%s'", bkpinfo->tmpdir); 2166 log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, bkpinfo->boot_loader); 2167 if (bkpinfo->media_size[0] < 0) 2168 { 2169 if (archiving_to_media) 2170 { 2171 fatal_error("Media size is less than zero."); 2172 } 2173 else 2174 { 2175 log_msg(2, "Warning - media size is less than zero."); 2176 bkpinfo->media_size[0] = 0; 2177 } 2178 } 2179 paranoid_free(tmp); 2180 paranoid_free(sz_size); 2181 paranoid_free(command); 2182 paranoid_free(comment); 2183 return(0); 2319 log_msg(3, "I think the NFS mount is mounted at %s", 2320 bkpinfo->isodir); 2321 } 2322 log_it("isodir = %s", bkpinfo->isodir); 2323 log_it("nfs_mount = '%s'", bkpinfo->nfs_mount); 2324 #endif 2325 2326 log_it("media device = %s", bkpinfo->media_device); 2327 log_it("media size = %ld", bkpinfo->media_size[1]); 2328 log_it("media type = %s", 2329 bkptype_to_string(bkpinfo->backup_media_type)); 2330 log_it("compression = %ld", bkpinfo->compression_level); 2331 log_it("include_paths = '%s'", bkpinfo->include_paths); 2332 log_it("exclude_paths = '%s'", bkpinfo->exclude_paths); 2333 log_it("scratchdir = '%s'", bkpinfo->scratchdir); 2334 log_it("tmpdir = '%s'", bkpinfo->tmpdir); 2335 log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, 2336 bkpinfo->boot_loader); 2337 if (bkpinfo->media_size[0] < 0) { 2338 if (archiving_to_media) { 2339 fatal_error("Media size is less than zero."); 2340 } else { 2341 log_msg(2, "Warning - media size is less than zero."); 2342 bkpinfo->media_size[0] = 0; 2343 } 2344 } 2345 paranoid_free(tmp); 2346 paranoid_free(sz_size); 2347 paranoid_free(command); 2348 paranoid_free(comment); 2349 return (0); 2184 2350 } 2185 2351 … … 2198 2364 char *list_of_NFS_devices_and_mounts(void) 2199 2365 { 2200 char *exclude_these_devices; 2201 char *exclude_these_directories; 2202 static char result_sz[512]; 2203 2204 malloc_string(exclude_these_devices); 2205 malloc_string(exclude_these_directories); 2206 strcpy(exclude_these_directories, call_program_and_get_last_line_of_output("mount -t coda,ncpfs,nfs,smbfs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'")); 2207 strcpy(exclude_these_devices, call_program_and_get_last_line_of_output("cat /etc/fstab | tr -s '\t' ' ' | grep -E '( (coda|ncpfs|nfs|smbfs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'")); 2208 sprintf(result_sz, "%s %s", exclude_these_directories, exclude_these_devices); 2209 paranoid_free(exclude_these_devices); 2210 paranoid_free(exclude_these_directories); 2211 return(result_sz); 2366 char *exclude_these_devices; 2367 char *exclude_these_directories; 2368 static char result_sz[512]; 2369 2370 malloc_string(exclude_these_devices); 2371 malloc_string(exclude_these_directories); 2372 strcpy(exclude_these_directories, 2373 call_program_and_get_last_line_of_output 2374 ("mount -t coda,ncpfs,nfs,smbfs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'")); 2375 strcpy(exclude_these_devices, 2376 call_program_and_get_last_line_of_output 2377 ("cat /etc/fstab | tr -s '\t' ' ' | grep -E '( (coda|ncpfs|nfs|smbfs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'")); 2378 sprintf(result_sz, "%s %s", exclude_these_directories, 2379 exclude_these_devices); 2380 paranoid_free(exclude_these_devices); 2381 paranoid_free(exclude_these_directories); 2382 return (result_sz); 2212 2383 } 2213 2384 … … 2223 2394 char *list_of_NFS_mounts_only(void) 2224 2395 { 2225 char *exclude_these_devices; 2226 char *exclude_these_directories; 2227 static char result_sz[512]; 2228 2229 malloc_string(exclude_these_devices); 2230 malloc_string(exclude_these_directories); 2231 strcpy(exclude_these_directories, call_program_and_get_last_line_of_output("mount -t coda,ncpfs,nfs,smbfs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'")); 2232 strcpy(exclude_these_devices, call_program_and_get_last_line_of_output("cat /etc/fstab | tr -s '\t' ' ' | grep -E '( (coda|ncpfs|nfs|smbfs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'")); 2233 sprintf(result_sz, "%s", exclude_these_directories); 2234 paranoid_free(exclude_these_devices); 2235 paranoid_free(exclude_these_directories); 2236 return(result_sz); 2396 char *exclude_these_devices; 2397 char *exclude_these_directories; 2398 static char result_sz[512]; 2399 2400 malloc_string(exclude_these_devices); 2401 malloc_string(exclude_these_directories); 2402 strcpy(exclude_these_directories, 2403 call_program_and_get_last_line_of_output 2404 ("mount -t coda,ncpfs,nfs,smbfs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'")); 2405 strcpy(exclude_these_devices, 2406 call_program_and_get_last_line_of_output 2407 ("cat /etc/fstab | tr -s '\t' ' ' | grep -E '( (coda|ncpfs|nfs|smbfs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'")); 2408 sprintf(result_sz, "%s", exclude_these_directories); 2409 paranoid_free(exclude_these_devices); 2410 paranoid_free(exclude_these_directories); 2411 return (result_sz); 2237 2412 } 2238 2413 … … 2250 2425 * @ingroup deviceGroup 2251 2426 */ 2252 void make_fifo(char*store_name_here, char*stub) 2253 { 2254 char *tmp; 2255 2256 malloc_string(tmp); 2257 assert_string_is_neither_NULL_nor_zerolength(stub); 2258 2259 sprintf(store_name_here, "%s%d%d", stub, (int)(random()%32768), (int)(random()%32768)); 2260 make_hole_for_file(store_name_here); 2261 mkfifo(store_name_here, S_IRWXU|S_IRWXG); 2262 sprintf(tmp, "chmod 770 %s", store_name_here); 2263 paranoid_system(tmp); 2264 paranoid_free(tmp); 2427 void make_fifo(char *store_name_here, char *stub) 2428 { 2429 char *tmp; 2430 2431 malloc_string(tmp); 2432 assert_string_is_neither_NULL_nor_zerolength(stub); 2433 2434 sprintf(store_name_here, "%s%d%d", stub, (int) (random() % 32768), 2435 (int) (random() % 32768)); 2436 make_hole_for_file(store_name_here); 2437 mkfifo(store_name_here, S_IRWXU | S_IRWXG); 2438 sprintf(tmp, "chmod 770 %s", store_name_here); 2439 paranoid_system(tmp); 2440 paranoid_free(tmp); 2265 2441 } 2266 2442 … … 2278 2454 void sensibly_set_tmpdir_and_scratchdir(struct s_bkpinfo *bkpinfo) 2279 2455 { 2280 2281 2282 2283 2284 2285 assert(bkpinfo!=NULL);2456 char *tmp, *command, *sz; 2457 2458 malloc_string(tmp); 2459 malloc_string(command); 2460 malloc_string(sz); 2461 assert(bkpinfo != NULL); 2286 2462 2287 2463 #ifdef __FreeBSD__ 2288 strcpy(tmp, call_program_and_get_last_line_of_output("df -m -t nonfs,msdosfs,ntfs,smbfs,smb,cifs | tr -s '\t' ' ' | grep -v none | grep -v Filesystem | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'")); 2464 strcpy(tmp, 2465 call_program_and_get_last_line_of_output 2466 ("df -m -t nonfs,msdosfs,ntfs,smbfs,smb,cifs | tr -s '\t' ' ' | grep -v none | grep -v Filesystem | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'")); 2289 2467 #else 2290 strcpy(tmp, call_program_and_get_last_line_of_output("df -m -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs | sed 's/ /devdev/' | tr -s '\t' ' ' | grep -v none | grep -v Filesystem | grep -v /dev/shm | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'")); 2291 #endif 2292 2293 if (tmp[0]!='/') { strcpy(sz, tmp); strcpy(tmp, "/"); strcat(tmp, sz); } 2294 if (!tmp[0]) { 2295 fatal_error ("I couldn't figure out the tempdir!"); 2296 } 2297 sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp, (int)(random()%32768)); 2298 log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir); 2299 2300 sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, (int)(random()%32768)); 2301 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir); 2302 2303 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir); 2304 2305 sprintf(command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp); 2306 paranoid_system(command); 2307 paranoid_free(tmp); 2308 paranoid_free(command); 2309 paranoid_free(sz); 2468 strcpy(tmp, 2469 call_program_and_get_last_line_of_output 2470 ("df -m -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs | sed 's/ /devdev/' | tr -s '\t' ' ' | grep -v none | grep -v Filesystem | grep -v /dev/shm | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'")); 2471 #endif 2472 2473 if (tmp[0] != '/') { 2474 strcpy(sz, tmp); 2475 strcpy(tmp, "/"); 2476 strcat(tmp, sz); 2477 } 2478 if (!tmp[0]) { 2479 fatal_error("I couldn't figure out the tempdir!"); 2480 } 2481 sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp, 2482 (int) (random() % 32768)); 2483 log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir); 2484 2485 sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, 2486 (int) (random() % 32768)); 2487 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir); 2488 2489 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, 2490 bkpinfo->scratchdir); 2491 2492 sprintf(command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp); 2493 paranoid_system(command); 2494 paranoid_free(tmp); 2495 paranoid_free(command); 2496 paranoid_free(sz); 2310 2497 } 2311 2498 … … 2326 2513 * @return TRUE if @p dev exists, FALSE if it doesn't. 2327 2514 */ 2328 bool set_dev_to_this_if_rx_OK(char *output, char*dev) 2329 { 2330 char *command; 2331 2332 malloc_string(command); 2333 if (!dev || dev[0]=='\0') { output[0]='\0'; return(FALSE); } 2515 bool set_dev_to_this_if_rx_OK(char *output, char *dev) 2516 { 2517 char *command; 2518 2519 malloc_string(command); 2520 if (!dev || dev[0] == '\0') { 2521 output[0] = '\0'; 2522 return (FALSE); 2523 } 2334 2524 // assert_string_is_neither_NULL_nor_zerolength(dev); 2335 log_msg(10, "Injecting %s", dev); 2336 inject_device(dev); 2337 if (!does_file_exist(dev)) { log_msg(10, "%s doesn't exist. Returning FALSE.", dev); return(FALSE); } 2338 sprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 512L, dev); 2339 if (!run_program_and_log_output(command, FALSE) && !run_program_and_log_output(command, FALSE)) 2340 { strcpy(output, dev); log_msg(4, "Found it - %s", dev); return(TRUE); } 2341 else 2342 { output[0]='\0'; log_msg(4, "It's not %s",dev); return(FALSE); } 2525 log_msg(10, "Injecting %s", dev); 2526 inject_device(dev); 2527 if (!does_file_exist(dev)) { 2528 log_msg(10, "%s doesn't exist. Returning FALSE.", dev); 2529 return (FALSE); 2530 } 2531 sprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 2532 512L, dev); 2533 if (!run_program_and_log_output(command, FALSE) 2534 && !run_program_and_log_output(command, FALSE)) { 2535 strcpy(output, dev); 2536 log_msg(4, "Found it - %s", dev); 2537 return (TRUE); 2538 } else { 2539 output[0] = '\0'; 2540 log_msg(4, "It's not %s", dev); 2541 return (FALSE); 2542 } 2343 2543 } 2344 2544 … … 2356 2556 int what_number_cd_is_this(struct s_bkpinfo *bkpinfo) 2357 2557 { 2358 int cd_number=-1;2359 2360 2361 2362 2363 2364 assert(bkpinfo!=NULL);2558 int cd_number = -1; 2559 char *mountdev; 2560 char *tmp; 2561 2562 malloc_string(mountdev); 2563 malloc_string(tmp); 2564 assert(bkpinfo != NULL); 2365 2565 // log_it("Asking what_number_cd_is_this"); 2366 if (g_ISO_restore_mode) 2367 { 2368 sprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'"); 2566 if (g_ISO_restore_mode) { 2567 sprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'"); 2369 2568 // log_it("tmp = %s", tmp); 2370 2569 2371 2372 2570 strcpy(mountdev, call_program_and_get_last_line_of_output(tmp)); 2571 strcat(mountdev, "/archives/THIS-CD-NUMBER"); 2373 2572 // log_it("mountdev = %s", mountdev); 2374 2573 cd_number = atoi(last_line_of_file(mountdev)); 2375 2574 // log_it("cd_number = %d", cd_number); 2376 paranoid_free(mountdev); 2377 paranoid_free(tmp); 2378 return(cd_number); 2379 } 2380 2381 strcpy(mountdev, bkpinfo->media_device); 2382 if (!mountdev[0]) 2383 { 2384 log_it("(what_number_cd_is_this) Warning - media_device unknown. Finding out..."); 2385 find_cdrom_device(bkpinfo->media_device, FALSE); 2386 } 2387 if (! is_this_device_mounted(MNT_CDROM)) 2388 { mount_CDROM_here(mountdev, MNT_CDROM); } 2389 cd_number = atoi(last_line_of_file(MNT_CDROM"/archives/THIS-CD-NUMBER")); 2575 paranoid_free(mountdev); 2576 paranoid_free(tmp); 2577 return (cd_number); 2578 } 2579 2580 strcpy(mountdev, bkpinfo->media_device); 2581 if (!mountdev[0]) { 2582 log_it 2583 ("(what_number_cd_is_this) Warning - media_device unknown. Finding out..."); 2584 find_cdrom_device(bkpinfo->media_device, FALSE); 2585 } 2586 if (!is_this_device_mounted(MNT_CDROM)) { 2587 mount_CDROM_here(mountdev, MNT_CDROM); 2588 } 2589 cd_number = 2590 atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER")); 2390 2591 // log_it("cd_number..later.. = %d", cd_number); 2391 paranoid_free(mountdev);2392 paranoid_free(tmp);2393 return(cd_number);2592 paranoid_free(mountdev); 2593 paranoid_free(tmp); 2594 return (cd_number); 2394 2595 } 2395 2596 … … 2407 2608 * The mountpoint (where it's mounted) will obviously be '/'. 2408 2609 */ 2409 char * 2410 where_is_root_mounted () 2411 { 2412 /*@ buffers *****************/ 2413 static char tmp[MAX_STR_LEN]; 2610 char *where_is_root_mounted() 2611 { 2612 /*@ buffers **************** */ 2613 static char tmp[MAX_STR_LEN]; 2414 2614 2415 2615 2416 2616 #ifdef __FreeBSD__ 2417 strcpy(tmp, call_program_and_get_last_line_of_output2418 2617 strcpy(tmp, call_program_and_get_last_line_of_output 2618 ("mount | grep \" on / \" | cut -d' ' -f1")); 2419 2619 #else 2420 strcpy (tmp, call_program_and_get_last_line_of_output 2421 ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//")); 2422 if (strstr(tmp, "/dev/cciss/")) { 2423 strcpy (tmp, call_program_and_get_last_line_of_output 2424 ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1")); 2425 } 2426 if (strstr(tmp, "/dev/md")) 2427 { 2428 strcpy(tmp, 2429 call_program_and_get_last_line_of_output 2430 ("mount | grep \" on / \" | cut -d' ' -f1")); 2431 } 2432 #endif 2433 2434 return (tmp); 2620 strcpy(tmp, call_program_and_get_last_line_of_output 2621 ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//")); 2622 if (strstr(tmp, "/dev/cciss/")) { 2623 strcpy(tmp, call_program_and_get_last_line_of_output 2624 ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1")); 2625 } 2626 if (strstr(tmp, "/dev/md")) { 2627 strcpy(tmp, 2628 call_program_and_get_last_line_of_output 2629 ("mount | grep \" on / \" | cut -d' ' -f1")); 2630 } 2631 #endif 2632 2633 return (tmp); 2435 2634 } 2436 2635 … … 2443 2642 */ 2444 2643 #ifdef __FreeBSD__ 2445 char which_boot_loader (char *which_device) 2446 { 2447 int count_lilos = 0; 2448 int count_grubs = 0; 2449 int count_boot0s = 0; 2450 int count_dangerouslydedicated = 0; 2451 2452 log_it ("looking at drive %s's MBR", which_device); 2453 if (does_string_exist_in_boot_block (which_device, "GRUB")) 2454 { count_grubs++; } 2455 if (does_string_exist_in_boot_block (which_device, "LILO")) 2456 { count_lilos++; } 2457 if (does_string_exist_in_boot_block (which_device, "Drive")) 2458 { count_boot0s++; } 2459 if (does_string_exist_in_first_N_blocks (which_device, "FreeBSD/i386", 17)) 2460 { count_dangerouslydedicated++; } 2461 log_it ("%d grubs and %d lilos and %d elilos and %d boot0s and %d DD\n", count_grubs, count_lilos, count_elilos, count_boot0s, count_dangerouslydedicated); 2462 2463 if (count_grubs && !count_lilos) 2464 { return ('G'); } 2465 else if (count_lilos && !count_grubs) 2466 { return ('L'); } 2467 else if (count_grubs == 1 && count_lilos == 1) 2468 { 2469 log_it ("I'll bet you used to use LILO but switched to GRUB..."); 2470 return ('G'); 2471 } 2472 else if (count_boot0s == 1) 2473 { return ('B'); } 2474 else if (count_dangerouslydedicated) 2475 { return ('D'); } 2476 else 2477 { 2478 log_it ("Unknown boot loader"); 2479 return ('U'); 2480 } 2644 char which_boot_loader(char *which_device) 2645 { 2646 int count_lilos = 0; 2647 int count_grubs = 0; 2648 int count_boot0s = 0; 2649 int count_dangerouslydedicated = 0; 2650 2651 log_it("looking at drive %s's MBR", which_device); 2652 if (does_string_exist_in_boot_block(which_device, "GRUB")) { 2653 count_grubs++; 2654 } 2655 if (does_string_exist_in_boot_block(which_device, "LILO")) { 2656 count_lilos++; 2657 } 2658 if (does_string_exist_in_boot_block(which_device, "Drive")) { 2659 count_boot0s++; 2660 } 2661 if (does_string_exist_in_first_N_blocks 2662 (which_device, "FreeBSD/i386", 17)) { 2663 count_dangerouslydedicated++; 2664 } 2665 log_it("%d grubs and %d lilos and %d elilos and %d boot0s and %d DD\n", 2666 count_grubs, count_lilos, count_elilos, count_boot0s, 2667 count_dangerouslydedicated); 2668 2669 if (count_grubs && !count_lilos) { 2670 return ('G'); 2671 } else if (count_lilos && !count_grubs) { 2672 return ('L'); 2673 } else if (count_grubs == 1 && count_lilos == 1) { 2674 log_it("I'll bet you used to use LILO but switched to GRUB..."); 2675 return ('G'); 2676 } else if (count_boot0s == 1) { 2677 return ('B'); 2678 } else if (count_dangerouslydedicated) { 2679 return ('D'); 2680 } else { 2681 log_it("Unknown boot loader"); 2682 return ('U'); 2683 } 2481 2684 } 2482 2685 2483 2686 #else 2484 2687 2485 char which_boot_loader 2486 { 2487 /*@ buffer ***************************************************** */2488 2489 2490 2491 /*@ pointers *************************************************** */2492 2493 2494 /*@ int ******************************************************** */2495 2496 2497 2498 /*@ end vars *************************************************** */2499 2500 2501 2688 char which_boot_loader(char *which_device) 2689 { 2690 /*@ buffer ***************************************************** */ 2691 char *list_drives_cmd; 2692 char *current_drive; 2693 2694 /*@ pointers *************************************************** */ 2695 FILE *pdrives; 2696 2697 /*@ int ******************************************************** */ 2698 int count_lilos = 0; 2699 int count_grubs = 0; 2700 2701 /*@ end vars *************************************************** */ 2702 2703 malloc_string(list_drives_cmd); 2704 malloc_string(current_drive); 2502 2705 2503 2706 #ifdef __IA64__ 2504 /* No choice for it */ 2505 return ('E'); 2506 #endif 2507 assert(which_device!=NULL); 2508 // sprintf (list_drives_cmd, 2509 // "fdisk -l | grep /dev | grep cyl | tr ':' ' ' | cut -d' ' -f2"); 2510 2511 sprintf (list_drives_cmd, 2512 // "parted2fdisk 2513 "fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", where_is_root_mounted()); 2514 log_it("list_drives_cmd = %s", list_drives_cmd); 2515 2516 if (!(pdrives = popen (list_drives_cmd, "r"))) 2517 { 2518 log_OS_error ("Unable to open list of drives"); 2519 paranoid_free(list_drives_cmd); 2520 paranoid_free(current_drive); 2521 return ('\0'); 2522 } 2523 for (fgets (current_drive, MAX_STR_LEN, pdrives); !feof (pdrives); 2524 fgets (current_drive, MAX_STR_LEN, pdrives)) 2525 { 2526 strip_spaces (current_drive); 2527 log_it ("looking at drive %s's MBR", current_drive); 2528 if (does_string_exist_in_boot_block (current_drive, "GRUB")) 2529 { 2530 count_grubs++; 2531 strcpy (which_device, current_drive); 2532 break; 2533 } 2534 if (does_string_exist_in_boot_block (current_drive, "LILO")) 2535 { 2536 count_lilos++; 2537 strcpy (which_device, current_drive); 2538 break; 2539 } 2540 } 2541 if (pclose (pdrives)) { log_OS_error("Cannot pclose pdrives"); } 2542 log_it ("%d grubs and %d lilos\n", count_grubs, count_lilos); 2543 paranoid_free(list_drives_cmd); 2544 paranoid_free(current_drive); 2545 if (count_grubs && !count_lilos) 2546 { 2547 return ('G'); 2548 } 2549 else if (count_lilos && !count_grubs) 2550 { 2551 return ('L'); 2552 } 2553 else if (count_grubs == 1 && count_lilos == 1) 2554 { 2555 log_it ("I'll bet you used to use LILO but switched to GRUB..."); 2556 return ('G'); 2557 } 2558 else 2559 { 2560 log_it ("Unknown boot loader"); 2561 return ('U'); 2562 } 2707 /* No choice for it */ 2708 return ('E'); 2709 #endif 2710 assert(which_device != NULL); 2711 // sprintf (list_drives_cmd, 2712 // "fdisk -l | grep /dev | grep cyl | tr ':' ' ' | cut -d' ' -f2"); 2713 2714 sprintf(list_drives_cmd, 2715 // "parted2fdisk 2716 "fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", 2717 where_is_root_mounted()); 2718 log_it("list_drives_cmd = %s", list_drives_cmd); 2719 2720 if (!(pdrives = popen(list_drives_cmd, "r"))) { 2721 log_OS_error("Unable to open list of drives"); 2722 paranoid_free(list_drives_cmd); 2723 paranoid_free(current_drive); 2724 return ('\0'); 2725 } 2726 for (fgets(current_drive, MAX_STR_LEN, pdrives); !feof(pdrives); 2727 fgets(current_drive, MAX_STR_LEN, pdrives)) { 2728 strip_spaces(current_drive); 2729 log_it("looking at drive %s's MBR", current_drive); 2730 if (does_string_exist_in_boot_block(current_drive, "GRUB")) { 2731 count_grubs++; 2732 strcpy(which_device, current_drive); 2733 break; 2734 } 2735 if (does_string_exist_in_boot_block(current_drive, "LILO")) { 2736 count_lilos++; 2737 strcpy(which_device, current_drive); 2738 break; 2739 } 2740 } 2741 if (pclose(pdrives)) { 2742 log_OS_error("Cannot pclose pdrives"); 2743 } 2744 log_it("%d grubs and %d lilos\n", count_grubs, count_lilos); 2745 paranoid_free(list_drives_cmd); 2746 paranoid_free(current_drive); 2747 if (count_grubs && !count_lilos) { 2748 return ('G'); 2749 } else if (count_lilos && !count_grubs) { 2750 return ('L'); 2751 } else if (count_grubs == 1 && count_lilos == 1) { 2752 log_it("I'll bet you used to use LILO but switched to GRUB..."); 2753 return ('G'); 2754 } else { 2755 log_it("Unknown boot loader"); 2756 return ('U'); 2757 } 2563 2758 } 2564 2759 #endif … … 2572 2767 * @return 0 for success, 1 for failure. 2573 2768 */ 2574 int 2575 zero_out_a_device (char *device) 2576 { 2577 FILE *fout; 2578 int i; 2579 2580 assert_string_is_neither_NULL_nor_zerolength(device); 2581 2582 log_it ("Zeroing drive %s", device); 2583 if (!(fout=fopen (device, "w"))) 2584 { 2585 log_OS_error ("Unable to open/write to device"); 2586 return (1); 2587 } 2588 for (i = 0; i < 16384; i++) 2589 { 2590 fputc ('\0', fout); 2591 } 2592 paranoid_fclose(fout); 2593 log_it ("Device successfully zeroed."); 2594 return (0); 2769 int zero_out_a_device(char *device) 2770 { 2771 FILE *fout; 2772 int i; 2773 2774 assert_string_is_neither_NULL_nor_zerolength(device); 2775 2776 log_it("Zeroing drive %s", device); 2777 if (!(fout = fopen(device, "w"))) { 2778 log_OS_error("Unable to open/write to device"); 2779 return (1); 2780 } 2781 for (i = 0; i < 16384; i++) { 2782 fputc('\0', fout); 2783 } 2784 paranoid_fclose(fout); 2785 log_it("Device successfully zeroed."); 2786 return (0); 2595 2787 } 2596 2788 … … 2602 2794 * @bug Won't work with file v4.0; needs to be written in C. 2603 2795 */ 2604 char *resolve_softlinks_to_get_to_actual_device_file(char *incoming)2605 { 2606 2607 2608 2609 2610 2611 2612 2613 struct stat statbuf; 2614 2615 2616 2617 2618 if (!does_file_exist(incoming)) 2619 { 2620 log_it("resolve_softlinks_to_get_to_actual_device_file --- device not found");2621 2622 } 2623 else 2624 { 2625 strcpy(curr_fname, incoming); 2626 lstat(curr_fname, &statbuf);2627 while(S_ISLNK(statbuf.st_mode)) 2628 { 2629 log_msg(1, "curr_fname = %s", curr_fname);2630 sprintf(command, "file %s", curr_fname);2631 strcpy(tmp, call_program_and_get_last_line_of_output(command));2632 for(p=tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; p--);2633 p++;2634 strcpy(scratch, p);2635 for(p=scratch; *p != '\0' && *p != '\''; p++);2636 *p = '\0';2637 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch);2638 if (scratch[0] == '/')2639 {2640 strcpy(curr_fname, scratch); // copy whole thing because it's an absolute softlink2641 }2642 else2643 { // copy over the basename cos it's a relative softlink2644 p = curr_fname + strlen(curr_fname);2645 while(p!=curr_fname && *p != '/') { p--;}2646 if (*p == '/') { p++;}2647 2648 2649 2650 }2651 2652 2653 2654 2655 2656 2657 return(output);2796 char *resolve_softlinks_to_get_to_actual_device_file(char *incoming) 2797 { 2798 static char output[MAX_STR_LEN]; 2799 char *command; 2800 char *curr_fname; 2801 char *scratch; 2802 char *tmp; 2803 char *p; 2804 2805 struct stat statbuf; 2806 command = malloc(1000); 2807 malloc_string(tmp); 2808 malloc_string(scratch); 2809 malloc_string(curr_fname); 2810 if (!does_file_exist(incoming)) { 2811 log_it 2812 ("resolve_softlinks_to_get_to_actual_device_file --- device not found"); 2813 strcpy(output, incoming); 2814 } else { 2815 strcpy(curr_fname, incoming); 2816 lstat(curr_fname, &statbuf); 2817 while (S_ISLNK(statbuf.st_mode)) { 2818 log_msg(1, "curr_fname = %s", curr_fname); 2819 sprintf(command, "file %s", curr_fname); 2820 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 2821 for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; 2822 p--); 2823 p++; 2824 strcpy(scratch, p); 2825 for (p = scratch; *p != '\0' && *p != '\''; p++); 2826 *p = '\0'; 2827 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, 2828 scratch); 2829 if (scratch[0] == '/') { 2830 strcpy(curr_fname, scratch); // copy whole thing because it's an absolute softlink 2831 } else { // copy over the basename cos it's a relative softlink 2832 p = curr_fname + strlen(curr_fname); 2833 while (p != curr_fname && *p != '/') { 2834 p--; 2835 } 2836 if (*p == '/') { 2837 p++; 2838 } 2839 strcpy(p, scratch); 2840 } 2841 lstat(curr_fname, &statbuf); 2842 } 2843 strcpy(output, curr_fname); 2844 log_it("resolved %s to %s", incoming, output); 2845 } 2846 paranoid_free(command); 2847 paranoid_free(curr_fname); 2848 paranoid_free(tmp); 2849 return (output); 2658 2850 } 2659 2851 … … 2666 2858 char *which_partition_format(const char *drive) 2667 2859 { 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 if (strstr(tmp,"GPT") == NULL) {2678 strcpy(output,"MBR");2679 2680 strcpy(output,"GPT");2681 2682 log_msg(0, "Found %s partition table format type",output);2683 2684 2685 return(output);2860 static char output[4]; 2861 char *tmp; 2862 char *command; 2863 2864 malloc_string(tmp); 2865 malloc_string(command); 2866 log_msg(0, "Looking for partition table format type"); 2867 sprintf(command, "fdisk -l %s | grep 'EFI GPT'", drive); 2868 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 2869 if (strstr(tmp, "GPT") == NULL) { 2870 strcpy(output, "MBR"); 2871 } else { 2872 strcpy(output, "GPT"); 2873 } 2874 log_msg(0, "Found %s partition table format type", output); 2875 paranoid_free(command); 2876 paranoid_free(tmp); 2877 return (output); 2686 2878 } 2687 2879 2688 2880 /* @} - end of deviceGroup */ 2689 -
trunk/mondo/mondo/common/libmondo-devices.h
r30 r59 1 1 /* 2 * $Id : libmondo-devices.h,v 1.4 2004/06/17 11:57:52 hugo Exp$2 * $Id$ 3 3 */ 4 4 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); 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, 16 char *device); 17 bool is_this_device_mounted(char *device_raw); 18 char *where_is_root_mounted(void); 19 char *make_vn(char *file); 20 int kick_vn(char *vn); 21 char which_boot_loader(char *which_device); 21 22 22 23 23 24 24 int find_cdrw_device 25 int find_cdrw_device(char *cdrw_device); 25 26 26 int interactively_obtain_media_parameters_from_user(struct s_bkpinfo *, bool); 27 int interactively_obtain_media_parameters_from_user(struct s_bkpinfo *, 28 bool); 27 29 28 30 29 31 30 void make_fifo(char *store_name_here, char*stub);32 void make_fifo(char *store_name_here, char *stub); 31 33 32 void insist_on_this_cd_number (struct s_bkpinfo* bkpinfo, int cd_number_i_want); 34 void insist_on_this_cd_number(struct s_bkpinfo *bkpinfo, 35 int cd_number_i_want); 33 36 34 37 int what_number_cd_is_this(struct s_bkpinfo *bkpinfo); 35 38 36 int eject_device(char *);39 int eject_device(char *); 37 40 38 41 char *list_of_NFS_devices_and_mounts(); … … 42 45 43 46 44 bool set_dev_to_this_if_rx_OK(char *output, char *dev);47 bool set_dev_to_this_if_rx_OK(char *output, char *dev); 45 48 46 49 47 50 void retract_CD_tray_and_defeat_autorun(void); 48 bool does_string_exist_in_first_N_blocks 51 bool does_string_exist_in_first_N_blocks(char *dev, char *str, int n); 49 52 50 int inject_device(char *dev);53 int inject_device(char *dev); 51 54 52 55 bool 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);56 char *resolve_softlinks_to_get_to_actual_device_file(char *incoming); 57 void set_g_cdrom_and_g_dvd_to_bkpinfo_value(struct s_bkpinfo *bkpinfo); 55 58 56 59 bool is_dev_an_NTFS_dev(char *bigfile_fname); -
trunk/mondo/mondo/common/libmondo-fifo-EXT.h
r30 r59 1 1 /* libfifo-EXT.h */ 2 2 3 extern FILE*open_device_via_buffer(char*dev, char direction, long internal_block_size); 3 extern FILE *open_device_via_buffer(char *dev, char direction, 4 long internal_block_size); 4 5 extern void sigpipe_occurred(int); 5 6 extern void kill_buffer(); 6 -
trunk/mondo/mondo/common/libmondo-fifo.h
r30 r59 1 1 /* libmondo-fifo.h 2 * $Id : libmondo-fifo.h,v 1.2 2004/06/10 15:29:12 hugo Exp$2 * $Id$ 3 3 */ 4 4 … … 8 8 9 9 10 FILE*open_device_via_buffer(char*dev, char direction, long internal_block_size); 10 FILE *open_device_via_buffer(char *dev, char direction, 11 long internal_block_size); 11 12 void sigpipe_occurred(int); 12 13 void kill_buffer(); -
trunk/mondo/mondo/common/libmondo-filelist-EXT.h
r30 r59 1 1 /* libmondo-filelist-EXT.h */ 2 2 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); 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, 8 char *string_to_add); 9 extern struct s_node *load_filelist(char *filelist_fname); 10 extern void reload_filelist(struct s_node *filelist); 11 extern void save_filelist(struct s_node *filelist, char *outfname); 12 extern void toggle_all_root_dirs_on(struct s_node *filelist); 13 extern void toggle_path_expandability(struct s_node *filelist, 14 char *pathname, bool on_or_off); 15 extern void toggle_path_selection(struct s_node *filelist, char *pathname, 16 bool on_or_off); 17 extern void toggle_node_selection(struct s_node *filelist, bool on_or_off); 18 extern int prepare_filelist(struct s_bkpinfo *bkpinfo); 16 19 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); 20 extern long save_filelist_entries_in_common(char *needles_list_fname, 21 struct s_node *filelist, 22 char *matches_fname, 23 bool use_star); 24 extern struct s_node *find_string_at_node(struct s_node *startnode, 25 char *string_to_find); 22 26 23 extern int add_list_of_files_to_filelist(struct s_node *filelist, char*list_of_files_fname, bool flag_em); 27 extern int add_list_of_files_to_filelist(struct s_node *filelist, 28 char *list_of_files_fname, 29 bool flag_em); 24 30 25 extern void show_filelist 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);31 extern void show_filelist(struct s_node *node); 32 extern int get_fattr_list(char *filelist, char *fattr_fname); 33 extern int get_acl_list(char *filelist, char *acl_fname); 34 extern int set_fattr_list(char *masklist, char *fattr_fname); 35 extern int set_acl_list(char *masklist, char *acl_fname); -
trunk/mondo/mondo/common/libmondo-filelist.c
r49 r59 1859 1859 } 1860 1860 } 1861 paranoid_free(fname);1861 paranoid_free(fname); 1862 1862 } 1863 1863 paranoid_fclose(fout); -
trunk/mondo/mondo/common/libmondo-filelist.h
r30 r59 1 1 /* libmondo-filelist.h 2 * $Id : libmondo-filelist.h,v 1.2 2004/06/10 15:29:12 hugo Exp$2 * $Id$ 3 3 */ 4 4 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); 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, 15 bool on_or_off); 16 void toggle_path_selection(struct s_node *filelist, char *pathname, 17 bool on_or_off); 18 void toggle_node_selection(struct s_node *filelist, bool on_or_off); 19 int prepare_filelist(struct s_bkpinfo *bkpinfo); 18 20 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);21 long save_filelist_entries_in_common(char *needles_list_fname, 22 struct s_node *filelist, 23 char *matches_fname, bool use_star); 24 struct s_node *find_string_at_node(struct s_node *startnode, 25 char *string_to_find); 24 26 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); 27 int add_list_of_files_to_filelist(struct s_node *filelist, 28 char *list_of_files_fname, bool flag_em); 29 void show_filelist(struct s_node *node); 30 int get_fattr_list(char *filelist, char *fattr_fname); 31 int get_acl_list(char *filelist, char *acl_fname); 32 int set_fattr_list(char *masklist, char *fattr_fname); 33 int set_acl_list(char *masklist, char *acl_fname); -
trunk/mondo/mondo/common/libmondo-files-EXT.h
r30 r59 4 4 #include <unistd.h> 5 5 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); 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, 20 char *comppath); 21 extern int make_hole_for_file(char *outfile_fname); 22 extern void make_list_of_files_to_ignore(char *ignorefiles_fname, 23 char *filelist_fname, 24 char *cklist_fname); 25 extern long noof_lines_that_match_wildcard(char *filelist_fname, 26 char *wildcard); 27 extern void register_pid(pid_t pid, char *name_str); 28 extern long long space_occupied_by_cd(char *mountpt); 29 extern int whine_if_not_found(char *fname); 30 extern int write_one_liner_data_file(char *fname, char *contents); 28 31 29 32 30 33 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); 34 extern long size_of_all_biggiefiles_K(struct s_bkpinfo *bkpinfo); 35 extern void copy_mondo_and_mindi_stuff_to_scratchdir(struct s_bkpinfo 36 *bkpinfo); 37 extern void store_nfs_config(struct s_bkpinfo *bkpinfo); 34 38 35 39 36 extern void estimate_noof_media_required (struct s_bkpinfo *bkpinfo,long);40 extern void estimate_noof_media_required(struct s_bkpinfo *bkpinfo, long); 37 41 38 extern bool is_this_file_compressed (char*);42 extern bool is_this_file_compressed(char *); 39 43 40 44 41 45 42 extern int make_hole_for_dir (char*outdir_fname);46 extern int make_hole_for_dir(char *outdir_fname); 43 47 44 extern long size_of_partition_in_mountlist_K(char *tmpdir, char*dev);48 extern long size_of_partition_in_mountlist_K(char *tmpdir, char *dev); 45 49 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 50 extern int make_grub_install_scriptlet(char *outfile); 51 extern int read_one_liner_data_file(char *fname, char *contents); 52 extern int mode_of_file(char *fname); -
trunk/mondo/mondo/common/libmondo-files.c
r30 r59 1 1 /* libmondo-files.c file manipulation 2 $Id : libmondo-files.c,v 1.5 2004/06/10 15:29:12 hugo Exp$2 $Id$ 3 3 . 4 4 … … 97 97 98 98 /*@unused@*/ 99 //static char cvsid[] = "$Id : libmondo-files.c,v 1.5 2004/06/10 15:29:12 hugo Exp$";99 //static char cvsid[] = "$Id$"; 100 100 101 101 extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN]; … … 114 114 * @note The returned string points to static storage that will be overwritten with each call. 115 115 */ 116 char * 117 calc_checksum_of_file (char *filename) 118 { 119 /*@ buffers ******************************************************/ 120 static char output[MAX_STR_LEN]; 121 char command[MAX_STR_LEN*2]; 122 char tmp[MAX_STR_LEN]; 123 124 /*@ pointers *****************************************************/ 125 char *p; 126 FILE *fin; 127 128 /*@ initialize pointers ******************************************/ 129 130 p = output; 131 132 /*@***************************************************************/ 133 134 assert_string_is_neither_NULL_nor_zerolength(filename); 135 if (does_file_exist (filename)) 136 { 137 sprintf (command, "md5sum \"%s\"", filename); 138 fin = popen (command, "r"); 139 if (fin) 140 { 141 (void) fgets (output, MAX_STR_LEN, fin); 142 p = strchr (output, ' '); 143 paranoid_pclose (fin); 144 } 145 } 146 else 147 { 148 sprintf (tmp, "File '%s' not found; cannot calc checksum", filename); 149 log_it (tmp); 150 } 151 if (p) 152 { 153 *p = '\0'; 154 } 155 return (output); 116 char *calc_checksum_of_file(char *filename) 117 { 118 /*@ buffers ***************************************************** */ 119 static char output[MAX_STR_LEN]; 120 char command[MAX_STR_LEN * 2]; 121 char tmp[MAX_STR_LEN]; 122 123 /*@ pointers **************************************************** */ 124 char *p; 125 FILE *fin; 126 127 /*@ initialize pointers ***************************************** */ 128 129 p = output; 130 131 /*@************************************************************** */ 132 133 assert_string_is_neither_NULL_nor_zerolength(filename); 134 if (does_file_exist(filename)) { 135 sprintf(command, "md5sum \"%s\"", filename); 136 fin = popen(command, "r"); 137 if (fin) { 138 (void) fgets(output, MAX_STR_LEN, fin); 139 p = strchr(output, ' '); 140 paranoid_pclose(fin); 141 } 142 } else { 143 sprintf(tmp, "File '%s' not found; cannot calc checksum", 144 filename); 145 log_it(tmp); 146 } 147 if (p) { 148 *p = '\0'; 149 } 150 return (output); 156 151 } 157 152 … … 164 159 * @note The returned string points to static storage that will be overwritten with each call. 165 160 */ 166 char * 167 calc_file_ugly_minichecksum (char *curr_fname) 168 { 169 170 /*@ buffers ******************************************************/ 171 static char curr_cksum[1000]; 172 173 /*@ pointers *****************************************************/ 174 175 /*@ structures ***************************************************/ 176 struct stat buf; 177 178 /*@ initialize data ****************************************************/ 179 curr_cksum[0] = '\0'; 180 181 /*@***************************************************************/ 182 183 assert_string_is_neither_NULL_nor_zerolength(curr_fname); 184 if (lstat (curr_fname, &buf)) 185 { 186 return (curr_cksum); // empty 187 } 188 189 sprintf (curr_cksum, "%ld-%ld-%ld", (long) (buf.st_size), 190 (long) (buf.st_mtime), (long) (buf.st_ctime)); 191 return (curr_cksum); 161 char *calc_file_ugly_minichecksum(char *curr_fname) 162 { 163 164 /*@ buffers ***************************************************** */ 165 static char curr_cksum[1000]; 166 167 /*@ pointers **************************************************** */ 168 169 /*@ structures ************************************************** */ 170 struct stat buf; 171 172 /*@ initialize data *************************************************** */ 173 curr_cksum[0] = '\0'; 174 175 /*@************************************************************** */ 176 177 assert_string_is_neither_NULL_nor_zerolength(curr_fname); 178 if (lstat(curr_fname, &buf)) { 179 return (curr_cksum); // empty 180 } 181 182 sprintf(curr_cksum, "%ld-%ld-%ld", (long) (buf.st_size), 183 (long) (buf.st_mtime), (long) (buf.st_ctime)); 184 return (curr_cksum); 192 185 } 193 186 … … 200 193 * @bug This function uses the shell and "wc -l"; it should probably be rewritten in C. 201 194 */ 202 long 203 count_lines_in_file (char *filename) 204 { 205 206 /*@ buffers ******************************************************/ 207 char command[MAX_STR_LEN*2]; 208 char incoming[MAX_STR_LEN]; 209 char tmp[MAX_STR_LEN]; 210 211 /*@ long *********************************************************/ 212 long noof_lines = -1L; 213 214 /*@ pointers *****************************************************/ 215 FILE *fin; 216 217 /*@ initialize [0] to null *********************************************/ 218 incoming[0] = '\0'; 219 220 assert_string_is_neither_NULL_nor_zerolength(filename); 221 if (!does_file_exist (filename)) 222 { 223 sprintf (tmp, 224 "%s does not exist, so I cannot found the number of lines in it", 225 filename); 226 log_it (tmp); 227 return (0); 228 } 229 sprintf (command, "cat %s | wc -l", filename); 230 if (!does_file_exist(filename)) { return(-1); } 231 fin = popen (command, "r"); 232 if (fin) 233 { 234 if (feof (fin)) 235 { 236 noof_lines = 0; 237 } 238 else 239 { 240 (void) fgets (incoming, MAX_STR_LEN - 1, fin); 241 while (strlen (incoming) > 0 242 && incoming[strlen (incoming) - 1] < 32) 243 { 244 incoming[strlen (incoming) - 1] = '\0'; 245 } 246 noof_lines = atol (incoming); 247 } 248 paranoid_pclose (fin); 249 } 250 return (noof_lines); 195 long count_lines_in_file(char *filename) 196 { 197 198 /*@ buffers ***************************************************** */ 199 char command[MAX_STR_LEN * 2]; 200 char incoming[MAX_STR_LEN]; 201 char tmp[MAX_STR_LEN]; 202 203 /*@ long ******************************************************** */ 204 long noof_lines = -1L; 205 206 /*@ pointers **************************************************** */ 207 FILE *fin; 208 209 /*@ initialize [0] to null ******************************************** */ 210 incoming[0] = '\0'; 211 212 assert_string_is_neither_NULL_nor_zerolength(filename); 213 if (!does_file_exist(filename)) { 214 sprintf(tmp, 215 "%s does not exist, so I cannot found the number of lines in it", 216 filename); 217 log_it(tmp); 218 return (0); 219 } 220 sprintf(command, "cat %s | wc -l", filename); 221 if (!does_file_exist(filename)) { 222 return (-1); 223 } 224 fin = popen(command, "r"); 225 if (fin) { 226 if (feof(fin)) { 227 noof_lines = 0; 228 } else { 229 (void) fgets(incoming, MAX_STR_LEN - 1, fin); 230 while (strlen(incoming) > 0 231 && incoming[strlen(incoming) - 1] < 32) { 232 incoming[strlen(incoming) - 1] = '\0'; 233 } 234 noof_lines = atol(incoming); 235 } 236 paranoid_pclose(fin); 237 } 238 return (noof_lines); 251 239 } 252 240 … … 257 245 * @return TRUE if it exists, FALSE otherwise. 258 246 */ 259 bool 260 does_file_exist (char *filename) 261 { 262 263 /*@ structures ***************************************************/ 264 struct stat buf; 265 266 /*@***************************************************************/ 267 268 assert(filename!=NULL); 269 // assert_string_is_neither_NULL_nor_zerolength(filename); 270 if (lstat (filename, &buf)) 271 { 272 log_msg(20, "%s does not exist", filename); 273 return (FALSE); 274 } 275 else 276 { 277 log_msg(20, "%s exists", filename); 278 return (TRUE); 279 } 247 bool does_file_exist(char *filename) 248 { 249 250 /*@ structures ************************************************** */ 251 struct stat buf; 252 253 /*@************************************************************** */ 254 255 assert(filename != NULL); 256 // assert_string_is_neither_NULL_nor_zerolength(filename); 257 if (lstat(filename, &buf)) { 258 log_msg(20, "%s does not exist", filename); 259 return (FALSE); 260 } else { 261 log_msg(20, "%s exists", filename); 262 return (TRUE); 263 } 280 264 } 281 265 … … 292 276 * while the modification is in progress. 293 277 */ 294 void 295 exclude_nonexistent_files (char *inout) 296 { 297 char infname[MAX_STR_LEN];298 char outfname[MAX_STR_LEN];299 char tmp[MAX_STR_LEN];300 char incoming[MAX_STR_LEN]; 301 302 /*@ int **********************************************************/303 int i; 304 305 /*@ pointers *****************************************************/306 FILE *fin, *fout; 307 308 309 /*@ end vars ************************************************************/ 310 311 assert_string_is_neither_NULL_nor_zerolength(inout);312 sprintf (infname, "%s.in", inout);313 sprintf (outfname, "%s", inout);314 sprintf (tmp, "cp -f %s %s", inout, infname);315 run_program_and_log_output (tmp, FALSE); 316 if (!(fin = fopen (infname, "r"))) { log_OS_error("Unable to openin infname"); return; } 317 if (!(fout = fopen (outfname, "w"))){log_OS_error("Unable to openout outfname"); return; } 318 for (fgets (incoming, MAX_STR_LEN, fin); !feof (fin); 319 fgets (incoming, MAX_STR_LEN, fin)) 320 { 321 i = strlen (incoming) - 1;322 if (i >= 0 && incoming[i] < 32) 323 {324 incoming[i] = '\0';325 }326 if (does_file_exist (incoming)) 327 {328 fprintf (fout, "%s\n", incoming);329 }330 else 331 {332 sprintf(tmp, "Excluding '%s'-nonexistent\n", incoming);333 log_it(tmp);334 }335 336 paranoid_fclose(fout);337 paranoid_fclose(fin);338 unlink(infname);278 void exclude_nonexistent_files(char *inout) 279 { 280 char infname[MAX_STR_LEN]; 281 char outfname[MAX_STR_LEN]; 282 char tmp[MAX_STR_LEN]; 283 char incoming[MAX_STR_LEN]; 284 285 /*@ int ********************************************************* */ 286 int i; 287 288 /*@ pointers **************************************************** */ 289 FILE *fin, *fout; 290 291 292 /*@ end vars *********************************************************** */ 293 294 assert_string_is_neither_NULL_nor_zerolength(inout); 295 sprintf(infname, "%s.in", inout); 296 sprintf(outfname, "%s", inout); 297 sprintf(tmp, "cp -f %s %s", inout, infname); 298 run_program_and_log_output(tmp, FALSE); 299 if (!(fin = fopen(infname, "r"))) { 300 log_OS_error("Unable to openin infname"); 301 return; 302 } 303 if (!(fout = fopen(outfname, "w"))) { 304 log_OS_error("Unable to openout outfname"); 305 return; 306 } 307 for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin); 308 fgets(incoming, MAX_STR_LEN, fin)) { 309 i = strlen(incoming) - 1; 310 if (i >= 0 && incoming[i] < 32) { 311 incoming[i] = '\0'; 312 } 313 if (does_file_exist(incoming)) { 314 fprintf(fout, "%s\n", incoming); 315 } else { 316 sprintf(tmp, "Excluding '%s'-nonexistent\n", incoming); 317 log_it(tmp); 318 } 319 } 320 paranoid_fclose(fout); 321 paranoid_fclose(fin); 322 unlink(infname); 339 323 } 340 324 … … 354 338 * @return 0 for success, 1 for failure. 355 339 */ 356 int figure_out_kernel_path_interactively_if_necessary(char*kernel) 357 { 358 char tmp[MAX_STR_LEN]; 359 360 if (!kernel[0]) 361 { strcpy(kernel, call_program_and_get_last_line_of_output("mindi --findkernel 2> /dev/null")); } 362 log_it("Calling Mindi with kernel path of '%s'", kernel); 363 while(!kernel[0]) 364 { 365 if (!ask_me_yes_or_no("Kernel not found or invalid. Choose another?")) 366 { return(1); } 367 if (!popup_and_get_string("Kernel path", "What is the full path and filename of your kernel, please?", kernel, MAX_STR_LEN/4)) 368 { fatal_error("Kernel not found. Please specify with the '-k' flag."); } 369 sprintf(tmp, "User says kernel is at %s", kernel); 370 log_it(tmp); 371 } 372 return(0); 340 int figure_out_kernel_path_interactively_if_necessary(char *kernel) 341 { 342 char tmp[MAX_STR_LEN]; 343 344 if (!kernel[0]) { 345 strcpy(kernel, 346 call_program_and_get_last_line_of_output 347 ("mindi --findkernel 2> /dev/null")); 348 } 349 log_it("Calling Mindi with kernel path of '%s'", kernel); 350 while (!kernel[0]) { 351 if (!ask_me_yes_or_no 352 ("Kernel not found or invalid. Choose another?")) { 353 return (1); 354 } 355 if (!popup_and_get_string 356 ("Kernel path", 357 "What is the full path and filename of your kernel, please?", 358 kernel, MAX_STR_LEN / 4)) { 359 fatal_error 360 ("Kernel not found. Please specify with the '-k' flag."); 361 } 362 sprintf(tmp, "User says kernel is at %s", kernel); 363 log_it(tmp); 364 } 365 return (0); 373 366 } 374 367 … … 387 380 * to nothing. 388 381 */ 389 char * 390 find_home_of_exe (char *fname) 391 { 392 /*@ buffers **********************/ 393 static char output[MAX_STR_LEN]; 394 char *incoming; 395 char *command; 396 397 malloc_string(incoming); 398 malloc_string(command); 399 incoming[0] = '\0'; 400 /*@********************************/ 401 402 assert_string_is_neither_NULL_nor_zerolength(fname); 403 sprintf (command, "which %s 2> /dev/null", fname); 404 strcpy (incoming, call_program_and_get_last_line_of_output (command)); 405 if (incoming[0] == '\0') 406 { 407 if (system("which file > /dev/null 2> /dev/null")) 382 char *find_home_of_exe(char *fname) 383 { 384 /*@ buffers ********************* */ 385 static char output[MAX_STR_LEN]; 386 char *incoming; 387 char *command; 388 389 malloc_string(incoming); 390 malloc_string(command); 391 incoming[0] = '\0'; 392 /*@******************************* */ 393 394 assert_string_is_neither_NULL_nor_zerolength(fname); 395 sprintf(command, "which %s 2> /dev/null", fname); 396 strcpy(incoming, call_program_and_get_last_line_of_output(command)); 397 if (incoming[0] == '\0') { 398 if (system("which file > /dev/null 2> /dev/null")) { 399 paranoid_free(incoming); 400 paranoid_free(command); 401 output[0] = '\0'; 402 return (NULL); // forget it :) 403 } 404 sprintf(command, 405 "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", 406 incoming); 407 strcpy(incoming, 408 call_program_and_get_last_line_of_output(command)); 409 } 410 if (incoming[0] == '\0') // yes, it is == '\0' twice, not once :) 408 411 { 409 paranoid_free(incoming); 410 paranoid_free(command); 411 output[0] = '\0'; return(NULL); // forget it :) 412 } 413 sprintf (command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", incoming); 414 strcpy (incoming, call_program_and_get_last_line_of_output (command)); 415 } 416 if (incoming[0] == '\0') // yes, it is == '\0' twice, not once :) 417 { 418 sprintf (command, "dirname %s 2> /dev/null", incoming); 419 strcpy (incoming, call_program_and_get_last_line_of_output (command)); 420 } 421 strcpy (output, incoming); 422 if (output[0] != '\0' && does_file_exist(output)) 423 { log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, incoming); } 424 else 425 { output[0]='\0'; log_msg(4, "find_home_of_exe() --- Could not find %s", fname); } 426 paranoid_free(incoming); 427 paranoid_free(command); 428 if (!output[0]) { return(NULL); } else { return (output); } 412 sprintf(command, "dirname %s 2> /dev/null", incoming); 413 strcpy(incoming, 414 call_program_and_get_last_line_of_output(command)); 415 } 416 strcpy(output, incoming); 417 if (output[0] != '\0' && does_file_exist(output)) { 418 log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, 419 incoming); 420 } else { 421 output[0] = '\0'; 422 log_msg(4, "find_home_of_exe() --- Could not find %s", fname); 423 } 424 paranoid_free(incoming); 425 paranoid_free(command); 426 if (!output[0]) { 427 return (NULL); 428 } else { 429 return (output); 430 } 429 431 } 430 432 … … 442 444 * @return The number found, or 0 if none. 443 445 */ 444 int 445 get_trackno_from_logfile (char *logfile) 446 { 447 448 /*@ pointers **********************************************************/ 449 FILE *fin; 450 451 /*@ int ***************************************************************/ 452 int trackno = 0; 453 size_t len = 0; 454 455 /*@ buffer *************************************************************/ 456 char datablock[32701]; 457 458 assert_string_is_neither_NULL_nor_zerolength(logfile); 459 if (!(fin = fopen (logfile, "r"))) { log_OS_error("Unable to open logfile"); fatal_error("Unable to open logfile to read trackno"); } 460 len = fread (datablock, 1, 32700, fin); 461 paranoid_fclose (fin); 462 if (len <= 0) 463 { 464 return (0); 465 } 466 for (; len > 0 && !isdigit (datablock[len - 1]); len--); 467 datablock[len--] = '\0'; 468 for (; len > 0 && isdigit (datablock[len - 1]); len--); 469 trackno = atoi (datablock + len); 470 /* 471 sprintf(tmp,"datablock=%s; trackno=%d",datablock+len, trackno); 472 log_it(tmp); 473 */ 474 return (trackno); 446 int get_trackno_from_logfile(char *logfile) 447 { 448 449 /*@ pointers ********************************************************* */ 450 FILE *fin; 451 452 /*@ int ************************************************************** */ 453 int trackno = 0; 454 size_t len = 0; 455 456 /*@ buffer ************************************************************ */ 457 char datablock[32701]; 458 459 assert_string_is_neither_NULL_nor_zerolength(logfile); 460 if (!(fin = fopen(logfile, "r"))) { 461 log_OS_error("Unable to open logfile"); 462 fatal_error("Unable to open logfile to read trackno"); 463 } 464 len = fread(datablock, 1, 32700, fin); 465 paranoid_fclose(fin); 466 if (len <= 0) { 467 return (0); 468 } 469 for (; len > 0 && !isdigit(datablock[len - 1]); len--); 470 datablock[len--] = '\0'; 471 for (; len > 0 && isdigit(datablock[len - 1]); len--); 472 trackno = atoi(datablock + len); 473 /* 474 sprintf(tmp,"datablock=%s; trackno=%d",datablock+len, trackno); 475 log_it(tmp); 476 */ 477 return (trackno); 475 478 } 476 479 … … 487 490 * @return The percentage found, or 0 for error. 488 491 */ 489 int 490 grab_percentage_from_last_line_of_file (char *filename) 491 { 492 493 /*@ buffers ******************************************************/ 494 char tmp[MAX_STR_LEN]; 495 char lastline[MAX_STR_LEN]; 496 char command[MAX_STR_LEN]; 497 /*@ pointers *****************************************************/ 498 char *p; 499 500 /*@ int's ********************************************************/ 501 int i; 502 503 for(i=NOOF_ERR_LINES-1; i>=0 && !strstr(err_log_lines[i], "% Done") && !strstr(err_log_lines[i], "% done"); i--); 504 if (i<0) 505 { 506 sprintf(command, "tail -n3 %s | fgrep -i \"%c\" | tail -n1 | awk '{print $0;}'", filename, '%'); 507 strcpy(lastline, call_program_and_get_last_line_of_output(command)); 508 if (!lastline[0]) 509 { 510 return(0); 511 } 512 } 513 else 514 { 515 strcpy(lastline, err_log_lines[i]); 516 } 517 518 p = strrchr(lastline, '%'); 519 if (p) { *p='\0'; } 492 int grab_percentage_from_last_line_of_file(char *filename) 493 { 494 495 /*@ buffers ***************************************************** */ 496 char tmp[MAX_STR_LEN]; 497 char lastline[MAX_STR_LEN]; 498 char command[MAX_STR_LEN]; 499 /*@ pointers **************************************************** */ 500 char *p; 501 502 /*@ int's ******************************************************* */ 503 int i; 504 505 for (i = NOOF_ERR_LINES - 1; 506 i >= 0 && !strstr(err_log_lines[i], "% Done") 507 && !strstr(err_log_lines[i], "% done"); i--); 508 if (i < 0) { 509 sprintf(command, 510 "tail -n3 %s | fgrep -i \"%c\" | tail -n1 | awk '{print $0;}'", 511 filename, '%'); 512 strcpy(lastline, 513 call_program_and_get_last_line_of_output(command)); 514 if (!lastline[0]) { 515 return (0); 516 } 517 } else { 518 strcpy(lastline, err_log_lines[i]); 519 } 520 521 p = strrchr(lastline, '%'); 522 if (p) { 523 *p = '\0'; 524 } 520 525 // log_msg(2, "lastline='%s', ", p, lastline); 521 if (!p) 522 { 523 return (0); 524 } 525 *p = '\0'; 526 for (p --; *p != ' ' && p != lastline; p--); 527 if (p != lastline) 528 { 529 p++; 530 } 531 i = atoi (p); 532 533 sprintf(tmp,"'%s' --> %d",p,i); 526 if (!p) { 527 return (0); 528 } 529 *p = '\0'; 530 for (p--; *p != ' ' && p != lastline; p--); 531 if (p != lastline) { 532 p++; 533 } 534 i = atoi(p); 535 536 sprintf(tmp, "'%s' --> %d", p, i); 534 537 // log_to_screen(tmp); 535 538 536 539 return (i); 537 540 } 538 541 … … 547 550 * @note The returned string points to static storage that will be overwritten with each call. 548 551 */ 549 char * 550 last_line_of_file (char *filename) 551 { 552 /*@ buffers ******************************************************/ 553 static char output[MAX_STR_LEN]; 554 static char command[MAX_STR_LEN*2]; 555 static char tmp[MAX_STR_LEN]; 556 557 /*@ pointers *****************************************************/ 558 FILE *fin; 559 560 /*@ end vars *****************************************************/ 561 562 if (!does_file_exist (filename)) 563 { 564 sprintf (tmp, "Tring to get last line of nonexistent file (%s)", 565 filename); 566 log_it (tmp); 567 output[0] = '\0'; 568 return (output); 569 } 570 sprintf (command, "cat %s | tail -n1", filename); 571 fin = popen (command, "r"); 572 (void) fgets (output, MAX_STR_LEN, fin); 573 paranoid_pclose (fin); 574 while (strlen (output) > 0 && output[strlen (output) - 1] < 32) 575 { 576 output[strlen (output) - 1] = '\0'; 577 } 578 return (output); 552 char *last_line_of_file(char *filename) 553 { 554 /*@ buffers ***************************************************** */ 555 static char output[MAX_STR_LEN]; 556 static char command[MAX_STR_LEN * 2]; 557 static char tmp[MAX_STR_LEN]; 558 559 /*@ pointers **************************************************** */ 560 FILE *fin; 561 562 /*@ end vars **************************************************** */ 563 564 if (!does_file_exist(filename)) { 565 sprintf(tmp, "Tring to get last line of nonexistent file (%s)", 566 filename); 567 log_it(tmp); 568 output[0] = '\0'; 569 return (output); 570 } 571 sprintf(command, "cat %s | tail -n1", filename); 572 fin = popen(command, "r"); 573 (void) fgets(output, MAX_STR_LEN, fin); 574 paranoid_pclose(fin); 575 while (strlen(output) > 0 && output[strlen(output) - 1] < 32) { 576 output[strlen(output) - 1] = '\0'; 577 } 578 return (output); 579 579 } 580 580 … … 584 584 * @return The length of the file, or -1 for error. 585 585 */ 586 long long 587 length_of_file (char *filename) 588 { 589 /*@ pointers ****************************************************/ 590 FILE *fin; 591 592 /*@ long long **************************************************/ 593 long long length; 594 595 fin = fopen (filename, "r"); 596 if (!fin) 597 { 598 log_it("filename=%s", filename); 599 log_OS_error("Unable to openin filename"); 600 return (-1); 601 } 602 fseek (fin, 0, SEEK_END); 603 length = ftell (fin); 604 paranoid_fclose (fin); 605 return (length); 586 long long length_of_file(char *filename) 587 { 588 /*@ pointers *************************************************** */ 589 FILE *fin; 590 591 /*@ long long ************************************************* */ 592 long long length; 593 594 fin = fopen(filename, "r"); 595 if (!fin) { 596 log_it("filename=%s", filename); 597 log_OS_error("Unable to openin filename"); 598 return (-1); 599 } 600 fseek(fin, 0, SEEK_END); 601 length = ftell(fin); 602 paranoid_fclose(fin); 603 return (length); 606 604 } 607 605 … … 613 611 */ 614 612 int 615 make_checksum_list_file (char *filelist, char *cksumlist, char *comppath) 616 { 617 /*@ pointers *****************************************************/ 618 FILE *fin; 619 FILE *fout; 620 621 /*@ int ********************************************************/ 622 int percentage; 623 int i; 624 int counter = 0; 625 626 /*@ buffer *******************************************************/ 627 char stub_fname[1000]; 628 char curr_fname[1000]; 629 char curr_cksum[1000]; 630 char tmp[1000]; 631 632 /*@ long [long] **************************************************/ 633 long long filelist_length; 634 long curr_pos; 635 long start_time; 636 long current_time; 637 long time_taken; 638 long time_remaining; 639 640 /*@ end vars ****************************************************/ 641 642 start_time = get_time (); 643 filelist_length = length_of_file (filelist); 644 sprintf (tmp, "filelist = %s; cksumlist = %s", filelist, cksumlist); 645 log_it (tmp); 646 fin = fopen (filelist, "r"); 647 if (fin == NULL) 648 { 649 log_OS_error ("Unable to fopen-in filelist"); 650 log_to_screen ("Can't open filelist"); 651 return (1); 652 } 653 fout = fopen (cksumlist, "w"); 654 if (fout == NULL) 655 { 656 log_OS_error ("Unable to openout cksumlist"); 657 paranoid_fclose (fin); 658 log_to_screen ("Can't open checksum list"); 659 return (1); 660 } 661 for (fgets (stub_fname, 999, fin); !feof (fin); 662 fgets (stub_fname, 999, fin)) 663 { 664 if (stub_fname[(i = strlen (stub_fname) - 1)] < 32) 665 { 666 stub_fname[i] = '\0'; 667 } 668 sprintf (tmp, "%s%s", comppath, stub_fname); 669 strcpy (curr_fname, tmp + 1); 670 strcpy (curr_cksum, calc_file_ugly_minichecksum (curr_fname)); 671 fprintf (fout, "%s\t%s\n", curr_fname, curr_cksum); 672 if (counter++ > 12) 673 { 674 current_time = get_time (); 675 counter = 0; 676 curr_fname[37] = '\0'; 677 curr_pos = ftell (fin) / 1024; 678 percentage = (int) (curr_pos * 100 / filelist_length); 679 time_taken = current_time - start_time; 680 if (percentage == 0) 681 { 682 /* printf("%0d%% done \r",percentage); */ 683 } 684 else 685 { 686 time_remaining = 687 time_taken * 100 / (long) (percentage) - time_taken; 688 sprintf (tmp, 689 "%02d%% done %02d:%02d taken %02d:%02d remaining %-37s\r", 690 percentage, (int) (time_taken / 60), 691 (int) (time_taken % 60), (int) (time_remaining / 60), 692 (int) (time_remaining % 60), curr_fname); 693 log_to_screen (tmp); 694 } 695 sync (); 696 } 697 } 698 paranoid_fclose (fout); 699 paranoid_fclose (fin); 700 log_it ("Done."); 701 return (0); 613 make_checksum_list_file(char *filelist, char *cksumlist, char *comppath) 614 { 615 /*@ pointers **************************************************** */ 616 FILE *fin; 617 FILE *fout; 618 619 /*@ int ******************************************************* */ 620 int percentage; 621 int i; 622 int counter = 0; 623 624 /*@ buffer ****************************************************** */ 625 char stub_fname[1000]; 626 char curr_fname[1000]; 627 char curr_cksum[1000]; 628 char tmp[1000]; 629 630 /*@ long [long] ************************************************* */ 631 long long filelist_length; 632 long curr_pos; 633 long start_time; 634 long current_time; 635 long time_taken; 636 long time_remaining; 637 638 /*@ end vars *************************************************** */ 639 640 start_time = get_time(); 641 filelist_length = length_of_file(filelist); 642 sprintf(tmp, "filelist = %s; cksumlist = %s", filelist, cksumlist); 643 log_it(tmp); 644 fin = fopen(filelist, "r"); 645 if (fin == NULL) { 646 log_OS_error("Unable to fopen-in filelist"); 647 log_to_screen("Can't open filelist"); 648 return (1); 649 } 650 fout = fopen(cksumlist, "w"); 651 if (fout == NULL) { 652 log_OS_error("Unable to openout cksumlist"); 653 paranoid_fclose(fin); 654 log_to_screen("Can't open checksum list"); 655 return (1); 656 } 657 for (fgets(stub_fname, 999, fin); !feof(fin); 658 fgets(stub_fname, 999, fin)) { 659 if (stub_fname[(i = strlen(stub_fname) - 1)] < 32) { 660 stub_fname[i] = '\0'; 661 } 662 sprintf(tmp, "%s%s", comppath, stub_fname); 663 strcpy(curr_fname, tmp + 1); 664 strcpy(curr_cksum, calc_file_ugly_minichecksum(curr_fname)); 665 fprintf(fout, "%s\t%s\n", curr_fname, curr_cksum); 666 if (counter++ > 12) { 667 current_time = get_time(); 668 counter = 0; 669 curr_fname[37] = '\0'; 670 curr_pos = ftell(fin) / 1024; 671 percentage = (int) (curr_pos * 100 / filelist_length); 672 time_taken = current_time - start_time; 673 if (percentage == 0) { 674 /* printf("%0d%% done \r",percentage); */ 675 } else { 676 time_remaining = 677 time_taken * 100 / (long) (percentage) - time_taken; 678 sprintf(tmp, 679 "%02d%% done %02d:%02d taken %02d:%02d remaining %-37s\r", 680 percentage, (int) (time_taken / 60), 681 (int) (time_taken % 60), 682 (int) (time_remaining / 60), 683 (int) (time_remaining % 60), curr_fname); 684 log_to_screen(tmp); 685 } 686 sync(); 687 } 688 } 689 paranoid_fclose(fout); 690 paranoid_fclose(fin); 691 log_it("Done."); 692 return (0); 702 693 } 703 694 … … 708 699 * @return The return value of @c mkdir. 709 700 */ 710 int make_hole_for_dir (char*outdir_fname)711 { 712 char tmp[MAX_STR_LEN*2];713 int res=0;714 715 716 717 718 return(res);701 int make_hole_for_dir(char *outdir_fname) 702 { 703 char tmp[MAX_STR_LEN * 2]; 704 int res = 0; 705 706 assert_string_is_neither_NULL_nor_zerolength(outdir_fname); 707 sprintf(tmp, "mkdir -p %s", outdir_fname); 708 res = system(tmp); 709 return (res); 719 710 } 720 711 … … 726 717 * @bug Return value unnecessary. 727 718 */ 728 int 729 make_hole_for_file (char *outfile_fname) 730 { 731 /*@ buffer *******************************************************/ 732 char command[MAX_STR_LEN*2]; 733 734 /*@ int *********************************************************/ 735 int res = 0; 736 737 /*@ end vars ****************************************************/ 738 739 assert_string_is_neither_NULL_nor_zerolength(outfile_fname); 740 assert(!strstr(outfile_fname, MNT_CDROM)); 741 assert(!strstr(outfile_fname, "/dev/cdrom")); 742 sprintf (command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname); 743 res += system (command); 744 sprintf (command, "rmdir \"%s\" 2> /dev/null", outfile_fname); 745 res += system (command); 746 sprintf (command, "rm -f \"%s\" 2> /dev/null", outfile_fname); 747 res += system (command); 748 unlink (outfile_fname); 749 return (0); 719 int make_hole_for_file(char *outfile_fname) 720 { 721 /*@ buffer ****************************************************** */ 722 char command[MAX_STR_LEN * 2]; 723 724 /*@ int ******************************************************** */ 725 int res = 0; 726 727 /*@ end vars *************************************************** */ 728 729 assert_string_is_neither_NULL_nor_zerolength(outfile_fname); 730 assert(!strstr(outfile_fname, MNT_CDROM)); 731 assert(!strstr(outfile_fname, "/dev/cdrom")); 732 sprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname); 733 res += system(command); 734 sprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname); 735 res += system(command); 736 sprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname); 737 res += system(command); 738 unlink(outfile_fname); 739 return (0); 750 740 } 751 741 … … 759 749 * @return The number of lines matched. 760 750 */ 761 long 762 noof_lines_that_match_wildcard (char *filelist_fname, char *wildcard) 763 { 764 /*@ long ********************************************************/ 765 long matches = 0; 766 767 /*@ pointers ****************************************************/ 768 FILE *fin; 769 770 /*@ buffers *****************************************************/ 771 char incoming[MAX_STR_LEN]; 772 773 /*@ end vars ****************************************************/ 774 775 776 fin = fopen (filelist_fname, "r"); 777 778 if (!fin) 779 { 780 log_OS_error("Unable to openin filelist_fname"); 781 return (0); 782 } 783 (void) fgets (incoming, MAX_STR_LEN - 1, fin); 784 while (!feof (fin)) 785 { 786 if (strstr (incoming, wildcard)) 787 { 788 matches++; 789 } 790 (void) fgets (incoming, MAX_STR_LEN - 1, fin); 791 } 792 paranoid_fclose (fin); 793 return (matches); 751 long noof_lines_that_match_wildcard(char *filelist_fname, char *wildcard) 752 { 753 /*@ long ******************************************************* */ 754 long matches = 0; 755 756 /*@ pointers *************************************************** */ 757 FILE *fin; 758 759 /*@ buffers **************************************************** */ 760 char incoming[MAX_STR_LEN]; 761 762 /*@ end vars *************************************************** */ 763 764 765 fin = fopen(filelist_fname, "r"); 766 767 if (!fin) { 768 log_OS_error("Unable to openin filelist_fname"); 769 return (0); 770 } 771 (void) fgets(incoming, MAX_STR_LEN - 1, fin); 772 while (!feof(fin)) { 773 if (strstr(incoming, wildcard)) { 774 matches++; 775 } 776 (void) fgets(incoming, MAX_STR_LEN - 1, fin); 777 } 778 paranoid_fclose(fin); 779 return (matches); 794 780 } 795 781 … … 804 790 * @note This function does not provide support against multiple instances, unless you check for that yourself. 805 791 */ 806 void register_pid(pid_t pid, char*name_str) 807 { 808 char tmp[MAX_STR_LEN+1], lockfile_fname[MAX_STR_LEN+1]; 809 int res; 810 FILE*fin; 811 812 sprintf(lockfile_fname, "/var/run/monitas-%s.pid", name_str); 813 if (!pid) 814 { 815 log_it("Unregistering PID"); 816 if (unlink(lockfile_fname)) { log_it( "Error unregistering PID"); } 817 return; 818 } 819 if (does_file_exist(lockfile_fname)) 820 { 821 tmp[0]='\0'; 822 if ((fin=fopen(lockfile_fname,"r"))) { (void) fgets(tmp, MAX_STR_LEN, fin); paranoid_fclose(fin); } 823 else { log_OS_error("Unable to openin lockfile_fname"); } 824 pid = (pid_t) atol(tmp); 825 sprintf(tmp, "ps %ld > /dev/null 2> /dev/null", (long int)pid); 826 res = system(tmp); 827 if (!res) 828 { 829 log_it ("I believe the daemon is already running. If it isn't, please delete %s and try again.", lockfile_fname); 830 } 831 } 832 sprintf(tmp, "echo %ld > %s 2> /dev/null", (long int)getpid(), lockfile_fname); 833 if (system(tmp)) { fatal_error( "Cannot register PID"); } 792 void register_pid(pid_t pid, char *name_str) 793 { 794 char tmp[MAX_STR_LEN + 1], lockfile_fname[MAX_STR_LEN + 1]; 795 int res; 796 FILE *fin; 797 798 sprintf(lockfile_fname, "/var/run/monitas-%s.pid", name_str); 799 if (!pid) { 800 log_it("Unregistering PID"); 801 if (unlink(lockfile_fname)) { 802 log_it("Error unregistering PID"); 803 } 804 return; 805 } 806 if (does_file_exist(lockfile_fname)) { 807 tmp[0] = '\0'; 808 if ((fin = fopen(lockfile_fname, "r"))) { 809 (void) fgets(tmp, MAX_STR_LEN, fin); 810 paranoid_fclose(fin); 811 } else { 812 log_OS_error("Unable to openin lockfile_fname"); 813 } 814 pid = (pid_t) atol(tmp); 815 sprintf(tmp, "ps %ld > /dev/null 2> /dev/null", (long int) pid); 816 res = system(tmp); 817 if (!res) { 818 log_it 819 ("I believe the daemon is already running. If it isn't, please delete %s and try again.", 820 lockfile_fname); 821 } 822 } 823 sprintf(tmp, "echo %ld > %s 2> /dev/null", (long int) getpid(), 824 lockfile_fname); 825 if (system(tmp)) { 826 fatal_error("Cannot register PID"); 827 } 834 828 } 835 829 … … 842 836 * @return The size of the partition in KB. 843 837 */ 844 long size_of_partition_in_mountlist_K(char *tmpdir, char*dev)845 { 846 847 848 849 850 851 852 sprintf(command,853 854 855 log_it(command);856 strcpy (sz_res, call_program_and_get_last_line_of_output(command));857 file_len_K = atol(sz_res);858 859 return(file_len_K);838 long size_of_partition_in_mountlist_K(char *tmpdir, char *dev) 839 { 840 char command[MAX_STR_LEN]; 841 char mountlist[MAX_STR_LEN]; 842 char sz_res[MAX_STR_LEN]; 843 long file_len_K; 844 845 sprintf(mountlist, "%s/mountlist.txt", tmpdir); 846 sprintf(command, 847 "cat %s/mountlist.txt | grep \"%s \" | head -n1 | awk '{print $4;}'", 848 tmpdir, dev); 849 log_it(command); 850 strcpy(sz_res, call_program_and_get_last_line_of_output(command)); 851 file_len_K = atol(sz_res); 852 log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K); 853 return (file_len_K); 860 854 } 861 855 … … 865 859 * @return The total size of all biggiefiles in KB. 866 860 */ 867 long 868 size_of_all_biggiefiles_K (struct s_bkpinfo *bkpinfo) 869 { 870 /*@ buffers ******************************************************/ 871 char *fname; 872 char *biggielist; 873 char *comment; 874 875 /*@ long *********************************************************/ 876 long scratchL = 0; 877 long file_len_K; 878 879 /*@ pointers ****************************************************/ 880 FILE *fin=NULL; 881 882 /*@ end vars ****************************************************/ 883 884 malloc_string(fname); 885 malloc_string(biggielist); 886 malloc_string(comment); 887 log_it ("Calculating size of all biggiefiles (in total)"); 888 sprintf (biggielist, "%s/biggielist.txt", bkpinfo->tmpdir); 889 log_it("biggielist = %s", biggielist); 890 if (!(fin = fopen (biggielist, "r"))) 891 { 892 log_OS_error 893 ("Cannot open biggielist. OK, so estimate is based on filesets only."); 894 } 895 else 896 { 897 log_msg(4, "Reading it..."); 898 for (fgets (fname, MAX_STR_LEN, fin); !feof (fin); 899 fgets (fname, MAX_STR_LEN, fin)) 900 { 901 if (fname[strlen(fname)-1]<=32) { fname[strlen(fname)-1]='\0'; } 902 if (0 == strncmp (fname, "/dev/", 5)) 903 { 904 file_len_K = get_phys_size_of_drive(fname)*1024L; 905 } 906 else 907 { 908 file_len_K = (long) (length_of_file (fname) / 1024); 909 } 910 if (file_len_K > 0) 911 { 912 scratchL += file_len_K; 913 log_msg(4, "%s --> %ld K", fname, file_len_K); 914 } 915 sprintf (comment, "After adding %s, scratchL+%ld now equals %ld", 916 fname, file_len_K, scratchL); 917 log_msg(4, comment); 918 if (feof(fin)) { break; } 919 } 920 } 921 log_it ("Closing..."); 922 paranoid_fclose (fin); 923 log_it ("Finished calculating total size of all biggiefiles"); 924 paranoid_free(fname); 925 paranoid_free(biggielist); 926 paranoid_free(comment); 927 return (scratchL); 861 long size_of_all_biggiefiles_K(struct s_bkpinfo *bkpinfo) 862 { 863 /*@ buffers ***************************************************** */ 864 char *fname; 865 char *biggielist; 866 char *comment; 867 868 /*@ long ******************************************************** */ 869 long scratchL = 0; 870 long file_len_K; 871 872 /*@ pointers *************************************************** */ 873 FILE *fin = NULL; 874 875 /*@ end vars *************************************************** */ 876 877 malloc_string(fname); 878 malloc_string(biggielist); 879 malloc_string(comment); 880 log_it("Calculating size of all biggiefiles (in total)"); 881 sprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir); 882 log_it("biggielist = %s", biggielist); 883 if (!(fin = fopen(biggielist, "r"))) { 884 log_OS_error 885 ("Cannot open biggielist. OK, so estimate is based on filesets only."); 886 } else { 887 log_msg(4, "Reading it..."); 888 for (fgets(fname, MAX_STR_LEN, fin); !feof(fin); 889 fgets(fname, MAX_STR_LEN, fin)) { 890 if (fname[strlen(fname) - 1] <= 32) { 891 fname[strlen(fname) - 1] = '\0'; 892 } 893 if (0 == strncmp(fname, "/dev/", 5)) { 894 file_len_K = get_phys_size_of_drive(fname) * 1024L; 895 } else { 896 file_len_K = (long) (length_of_file(fname) / 1024); 897 } 898 if (file_len_K > 0) { 899 scratchL += file_len_K; 900 log_msg(4, "%s --> %ld K", fname, file_len_K); 901 } 902 sprintf(comment, 903 "After adding %s, scratchL+%ld now equals %ld", fname, 904 file_len_K, scratchL); 905 log_msg(4, comment); 906 if (feof(fin)) { 907 break; 908 } 909 } 910 } 911 log_it("Closing..."); 912 paranoid_fclose(fin); 913 log_it("Finished calculating total size of all biggiefiles"); 914 paranoid_free(fname); 915 paranoid_free(biggielist); 916 paranoid_free(comment); 917 return (scratchL); 928 918 } 929 919 … … 934 924 * @return The amount of space occupied in KB. 935 925 */ 936 long long 937 space_occupied_by_cd (char *mountpt) 938 { 939 /*@ buffer *******************************************************/ 940 char tmp[MAX_STR_LEN]; 941 char command[MAX_STR_LEN*2]; 942 long long llres; 943 /*@ pointers *****************************************************/ 944 char *p; 945 FILE *fin; 946 947 /*@ end vars ****************************************************/ 948 949 sprintf (command, "du -sk %s", mountpt); 950 fin = popen (command, "r"); 951 (void) fgets (tmp, MAX_STR_LEN, fin); 952 paranoid_pclose (fin); 953 p = strchr (tmp, '\t'); 954 if (p) 955 { 956 *p = '\0'; 957 } 958 for(p=tmp,llres=0; *p!='\0'; p++) 959 { 960 llres*=10; 961 llres+=(int)(*p - '0'); 962 } 963 return (llres); 926 long long space_occupied_by_cd(char *mountpt) 927 { 928 /*@ buffer ****************************************************** */ 929 char tmp[MAX_STR_LEN]; 930 char command[MAX_STR_LEN * 2]; 931 long long llres; 932 /*@ pointers **************************************************** */ 933 char *p; 934 FILE *fin; 935 936 /*@ end vars *************************************************** */ 937 938 sprintf(command, "du -sk %s", mountpt); 939 fin = popen(command, "r"); 940 (void) fgets(tmp, MAX_STR_LEN, fin); 941 paranoid_pclose(fin); 942 p = strchr(tmp, '\t'); 943 if (p) { 944 *p = '\0'; 945 } 946 for (p = tmp, llres = 0; *p != '\0'; p++) { 947 llres *= 10; 948 llres += (int) (*p - '0'); 949 } 950 return (llres); 964 951 } 965 952 … … 972 959 * @ingroup utilityGroup 973 960 */ 974 unsigned int 975 updcrc (unsigned int crc, unsigned int c) 976 { 977 unsigned int tmp; 978 tmp = (crc >> 8) ^ c; 979 crc = (crc << 8) ^ crctttab[tmp & 255]; 980 return crc; 961 unsigned int updcrc(unsigned int crc, unsigned int c) 962 { 963 unsigned int tmp; 964 tmp = (crc >> 8) ^ c; 965 crc = (crc << 8) ^ crctttab[tmp & 255]; 966 return crc; 981 967 } 982 968 … … 988 974 * @ingroup utilityGroup 989 975 */ 990 unsigned int 991 updcrcr (unsigned int crc, unsigned int c) 992 { 993 unsigned int tmp; 994 tmp = crc ^ c; 995 crc = (crc >> 8) ^ crc16tab[tmp & 0xff]; 996 return crc; 976 unsigned int updcrcr(unsigned int crc, unsigned int c) 977 { 978 unsigned int tmp; 979 tmp = crc ^ c; 980 crc = (crc >> 8) ^ crc16tab[tmp & 0xff]; 981 return crc; 997 982 } 998 983 … … 1006 991 * @return 0 if it's found, nonzero if not. 1007 992 */ 1008 int 1009 whine_if_not_found (char *fname) 1010 { 1011 /*@ buffers ****/ 1012 char command[MAX_STR_LEN*2]; 1013 char errorstr[MAX_STR_LEN]; 1014 1015 1016 sprintf (command, "which %s > /dev/null 2> /dev/null", fname); 1017 sprintf (errorstr, "Please install '%s'. I cannot find it on your system.", 1018 fname); 1019 if (system (command)) 1020 { 1021 log_to_screen (errorstr); 1022 log_to_screen 1023 ("There may be hyperlink at http://www.mondorescue.com which"); 1024 log_to_screen ("will take you to the relevant (missing) package."); 1025 return (1); 1026 } 1027 else 1028 { 1029 return (0); 1030 } 993 int whine_if_not_found(char *fname) 994 { 995 /*@ buffers *** */ 996 char command[MAX_STR_LEN * 2]; 997 char errorstr[MAX_STR_LEN]; 998 999 1000 sprintf(command, "which %s > /dev/null 2> /dev/null", fname); 1001 sprintf(errorstr, 1002 "Please install '%s'. I cannot find it on your system.", 1003 fname); 1004 if (system(command)) { 1005 log_to_screen(errorstr); 1006 log_to_screen 1007 ("There may be hyperlink at http://www.mondorescue.com which"); 1008 log_to_screen("will take you to the relevant (missing) package."); 1009 return (1); 1010 } else { 1011 return (0); 1012 } 1031 1013 } 1032 1014 … … 1043 1025 * @return 0 for success, 1 for failure. 1044 1026 */ 1045 int 1046 write_one_liner_data_file (char *fname, char *contents) 1047 { 1048 /*@ pointers ****************************************************/1049 FILE *fout;1050 int res=0; 1051 1052 /*@ end vars ****************************************************/ 1053 1054 assert_string_is_neither_NULL_nor_zerolength(fname); 1055 if (!contents) { log_it("%d: Warning - writing NULL to %s", __LINE__, fname); } 1056 if (!(fout = fopen (fname, "w"))) 1057 1058 1059 1060 1061 1062 fprintf(fout, "%s\n", contents);1063 paranoid_fclose(fout);1064 1027 int write_one_liner_data_file(char *fname, char *contents) 1028 { 1029 /*@ pointers *************************************************** */ 1030 FILE *fout; 1031 int res = 0; 1032 1033 /*@ end vars *************************************************** */ 1034 1035 assert_string_is_neither_NULL_nor_zerolength(fname); 1036 if (!contents) { 1037 log_it("%d: Warning - writing NULL to %s", __LINE__, fname); 1038 } 1039 if (!(fout = fopen(fname, "w"))) { 1040 log_it("fname=%s"); 1041 log_OS_error("Unable to openout fname"); 1042 return (1); 1043 } 1044 fprintf(fout, "%s\n", contents); 1045 paranoid_fclose(fout); 1046 return (res); 1065 1047 } 1066 1048 … … 1073 1055 * @return 0 for success, nonzero for failure. 1074 1056 */ 1075 int 1076 read_one_liner_data_file (char *fname, char *contents) 1077 { 1078 /*@ pointers ****************************************************/ 1079 FILE *fin; 1080 int res=0; 1081 int i; 1082 1083 /*@ end vars ****************************************************/ 1084 1085 assert_string_is_neither_NULL_nor_zerolength(fname); 1086 if (!contents) { log_it("%d: Warning - reading NULL from %s", __LINE__, fname); } 1087 if (!(fin = fopen (fname, "r"))) 1088 { 1089 log_it("fname=%s", fname); 1090 log_OS_error("Unable to openin fname"); 1091 return (1); 1092 } 1093 fscanf (fin, "%s\n", contents); 1094 i = strlen(contents); 1095 if (i>0 && contents[i-1] < 32) { contents[i-1] = '\0'; } 1096 paranoid_fclose (fin); 1097 return (res); 1057 int read_one_liner_data_file(char *fname, char *contents) 1058 { 1059 /*@ pointers *************************************************** */ 1060 FILE *fin; 1061 int res = 0; 1062 int i; 1063 1064 /*@ end vars *************************************************** */ 1065 1066 assert_string_is_neither_NULL_nor_zerolength(fname); 1067 if (!contents) { 1068 log_it("%d: Warning - reading NULL from %s", __LINE__, fname); 1069 } 1070 if (!(fin = fopen(fname, "r"))) { 1071 log_it("fname=%s", fname); 1072 log_OS_error("Unable to openin fname"); 1073 return (1); 1074 } 1075 fscanf(fin, "%s\n", contents); 1076 i = strlen(contents); 1077 if (i > 0 && contents[i - 1] < 32) { 1078 contents[i - 1] = '\0'; 1079 } 1080 paranoid_fclose(fin); 1081 return (res); 1098 1082 } 1099 1083 … … 1116 1100 * - @c bkpinfo->tmpdir 1117 1101 */ 1118 void 1119 copy_mondo_and_mindi_stuff_to_scratchdir (struct s_bkpinfo *bkpinfo) 1120 { 1121 /*@ Char buffers ***/ 1122 char command[MAX_STR_LEN*2]; 1123 char tmp[MAX_STR_LEN]; 1124 char old_pwd[MAX_STR_LEN]; 1125 1126 mvaddstr_and_log_it (g_currentY, 0, 1127 "Copying Mondo's core files to the scratch directory"); 1128 1129 log_msg(4, "g_mondo_home='%s'", g_mondo_home); 1130 if (strlen(g_mondo_home)<2) 1131 { find_and_store_mondoarchives_home(g_mondo_home); } 1132 sprintf (command, CP_BIN " --parents -pRdf %s %s", g_mondo_home, 1133 bkpinfo->scratchdir); 1134 1135 log_msg(4, "command = %s", command); 1136 if (run_program_and_log_output (command, 1)) 1137 { 1138 fatal_error ("Failed to copy Mondo's stuff to scratchdir"); 1139 } 1140 1141 sprintf(tmp, "%s/payload.tgz", g_mondo_home); 1142 if (does_file_exist(tmp)) 1143 { 1144 log_it("Untarring payload %s to scratchdir %s", tmp, bkpinfo->scratchdir); 1145 (void) getcwd (old_pwd, MAX_STR_LEN -1); 1146 chdir (bkpinfo->scratchdir); 1147 sprintf(command, "tar -zxvf %s", tmp); 1148 if (run_program_and_log_output(command, FALSE)) 1149 { fatal_error ("Failed to untar payload"); } 1150 chdir (old_pwd); 1151 } 1152 1153 sprintf (command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, 1154 bkpinfo->scratchdir); 1155 1156 if (run_program_and_log_output (command, FALSE)) 1157 { 1158 fatal_error ("Failed to copy LAST-FILELIST-NUMBER to scratchdir"); 1159 } 1160 1161 strcpy (tmp, 1162 call_program_and_get_last_line_of_output ("which mondorestore")); 1163 if (!tmp[0]) { fatal_error("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?"); } 1164 sprintf (command, "cp -f %s %s", tmp, bkpinfo->tmpdir); 1165 if (run_program_and_log_output (command, FALSE)) 1166 { 1167 fatal_error ("Failed to copy mondorestore to tmpdir"); 1168 } 1169 1170 sprintf (command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir); 1171 paranoid_system (command); 1172 1173 if (bkpinfo->postnuke_tarball[0]) 1174 { 1175 sprintf (command, "cp -f %s %s/post-nuke.tgz", bkpinfo->postnuke_tarball, bkpinfo->tmpdir); 1176 if (run_program_and_log_output (command, FALSE)) 1177 { fatal_error("Unable to copy post-nuke tarball to tmpdir"); } 1178 } 1179 1180 1181 mvaddstr_and_log_it (g_currentY++, 74, "Done."); 1102 void copy_mondo_and_mindi_stuff_to_scratchdir(struct s_bkpinfo *bkpinfo) 1103 { 1104 /*@ Char buffers ** */ 1105 char command[MAX_STR_LEN * 2]; 1106 char tmp[MAX_STR_LEN]; 1107 char old_pwd[MAX_STR_LEN]; 1108 1109 mvaddstr_and_log_it(g_currentY, 0, 1110 "Copying Mondo's core files to the scratch directory"); 1111 1112 log_msg(4, "g_mondo_home='%s'", g_mondo_home); 1113 if (strlen(g_mondo_home) < 2) { 1114 find_and_store_mondoarchives_home(g_mondo_home); 1115 } 1116 sprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home, 1117 bkpinfo->scratchdir); 1118 1119 log_msg(4, "command = %s", command); 1120 if (run_program_and_log_output(command, 1)) { 1121 fatal_error("Failed to copy Mondo's stuff to scratchdir"); 1122 } 1123 1124 sprintf(tmp, "%s/payload.tgz", g_mondo_home); 1125 if (does_file_exist(tmp)) { 1126 log_it("Untarring payload %s to scratchdir %s", tmp, 1127 bkpinfo->scratchdir); 1128 (void) getcwd(old_pwd, MAX_STR_LEN - 1); 1129 chdir(bkpinfo->scratchdir); 1130 sprintf(command, "tar -zxvf %s", tmp); 1131 if (run_program_and_log_output(command, FALSE)) { 1132 fatal_error("Failed to untar payload"); 1133 } 1134 chdir(old_pwd); 1135 } 1136 1137 sprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, 1138 bkpinfo->scratchdir); 1139 1140 if (run_program_and_log_output(command, FALSE)) { 1141 fatal_error("Failed to copy LAST-FILELIST-NUMBER to scratchdir"); 1142 } 1143 1144 strcpy(tmp, 1145 call_program_and_get_last_line_of_output("which mondorestore")); 1146 if (!tmp[0]) { 1147 fatal_error 1148 ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?"); 1149 } 1150 sprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir); 1151 if (run_program_and_log_output(command, FALSE)) { 1152 fatal_error("Failed to copy mondorestore to tmpdir"); 1153 } 1154 1155 sprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir); 1156 paranoid_system(command); 1157 1158 if (bkpinfo->postnuke_tarball[0]) { 1159 sprintf(command, "cp -f %s %s/post-nuke.tgz", 1160 bkpinfo->postnuke_tarball, bkpinfo->tmpdir); 1161 if (run_program_and_log_output(command, FALSE)) { 1162 fatal_error("Unable to copy post-nuke tarball to tmpdir"); 1163 } 1164 } 1165 1166 1167 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1182 1168 } 1183 1169 … … 1194 1180 * - @c tmpdir 1195 1181 */ 1196 void 1197 store_nfs_config (struct s_bkpinfo *bkpinfo) 1198 { 1199 1200 /*@ buffers *********/ 1201 char outfile[MAX_STR_LEN]; 1202 char nfs_dev[MAX_STR_LEN]; 1203 char nfs_mount[MAX_STR_LEN]; 1204 char nfs_client_ipaddr[MAX_STR_LEN]; 1205 char nfs_server_ipaddr[MAX_STR_LEN]; 1206 char tmp[MAX_STR_LEN]; 1207 char command[MAX_STR_LEN*2]; 1208 1209 /*@ pointers ******/ 1210 char *p; 1211 FILE *fout; 1212 1213 1214 1215 log_it ("Storing NFS configuration"); 1216 strcpy (tmp, bkpinfo->nfs_mount); 1217 p = strchr (tmp, ':'); 1218 if (!p) 1219 { 1220 fatal_error 1221 ("NFS mount doesn't have a colon in it, e.g. 192.168.1.4:/home/nfs"); 1222 } 1223 *(p++) = '\0'; 1224 strcpy (nfs_server_ipaddr, tmp); 1225 strcpy (nfs_mount, p); 1226 sprintf (command, 1227 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1"); 1228 strcpy (nfs_dev, call_program_and_get_last_line_of_output (command)); 1229 sprintf (command, 1230 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2"); 1231 strcpy (nfs_client_ipaddr, 1232 call_program_and_get_last_line_of_output (command)); 1233 sprintf (tmp, "nfs_client_ipaddr=%s; nfs_server_ipaddr=%s; nfs_mount=%s", 1234 nfs_client_ipaddr, nfs_server_ipaddr, nfs_mount); 1235 if (strlen (nfs_dev) < 2) 1236 { 1237 fatal_error 1238 ("Unable to find ethN (eth0, eth1, ...) adapter via NFS mount you specified."); 1239 } 1240 sprintf (outfile, "%s/start-nfs", bkpinfo->tmpdir); 1241 sprintf (tmp, "outfile = %s", outfile); 1242 log_it (tmp); 1243 if (!(fout = fopen (outfile, "w"))) 1244 { 1245 fatal_error ("Cannot store NFS config"); 1246 } 1247 fprintf (fout, "ifconfig lo 127.0.0.1 # config loopback\n"); 1248 fprintf (fout, "ifconfig %s %s; # config client\n", nfs_dev, 1249 nfs_client_ipaddr); 1250 fprintf (fout, "ping -c1 %s; # ping server\n", nfs_server_ipaddr); 1251 fprintf (fout, "mount -t nfs -o nolock %s /tmp/isodir\n", bkpinfo->nfs_mount); 1252 fprintf (fout, "exit 0\n"); 1253 paranoid_fclose (fout); 1254 chmod (outfile, 0777); 1255 make_hole_for_dir( "/var/cache/mondo-archive"); 1182 void store_nfs_config(struct s_bkpinfo *bkpinfo) 1183 { 1184 1185 /*@ buffers ******** */ 1186 char outfile[MAX_STR_LEN]; 1187 char nfs_dev[MAX_STR_LEN]; 1188 char nfs_mount[MAX_STR_LEN]; 1189 char nfs_client_ipaddr[MAX_STR_LEN]; 1190 char nfs_server_ipaddr[MAX_STR_LEN]; 1191 char tmp[MAX_STR_LEN]; 1192 char command[MAX_STR_LEN * 2]; 1193 1194 /*@ pointers ***** */ 1195 char *p; 1196 FILE *fout; 1197 1198 1199 1200 log_it("Storing NFS configuration"); 1201 strcpy(tmp, bkpinfo->nfs_mount); 1202 p = strchr(tmp, ':'); 1203 if (!p) { 1204 fatal_error 1205 ("NFS mount doesn't have a colon in it, e.g. 192.168.1.4:/home/nfs"); 1206 } 1207 *(p++) = '\0'; 1208 strcpy(nfs_server_ipaddr, tmp); 1209 strcpy(nfs_mount, p); 1210 sprintf(command, 1211 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1"); 1212 strcpy(nfs_dev, call_program_and_get_last_line_of_output(command)); 1213 sprintf(command, 1214 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2"); 1215 strcpy(nfs_client_ipaddr, 1216 call_program_and_get_last_line_of_output(command)); 1217 sprintf(tmp, 1218 "nfs_client_ipaddr=%s; nfs_server_ipaddr=%s; nfs_mount=%s", 1219 nfs_client_ipaddr, nfs_server_ipaddr, nfs_mount); 1220 if (strlen(nfs_dev) < 2) { 1221 fatal_error 1222 ("Unable to find ethN (eth0, eth1, ...) adapter via NFS mount you specified."); 1223 } 1224 sprintf(outfile, "%s/start-nfs", bkpinfo->tmpdir); 1225 sprintf(tmp, "outfile = %s", outfile); 1226 log_it(tmp); 1227 if (!(fout = fopen(outfile, "w"))) { 1228 fatal_error("Cannot store NFS config"); 1229 } 1230 fprintf(fout, "ifconfig lo 127.0.0.1 # config loopback\n"); 1231 fprintf(fout, "ifconfig %s %s; # config client\n", nfs_dev, 1232 nfs_client_ipaddr); 1233 fprintf(fout, "ping -c1 %s; # ping server\n", nfs_server_ipaddr); 1234 fprintf(fout, "mount -t nfs -o nolock %s /tmp/isodir\n", 1235 bkpinfo->nfs_mount); 1236 fprintf(fout, "exit 0\n"); 1237 paranoid_fclose(fout); 1238 chmod(outfile, 0777); 1239 make_hole_for_dir("/var/cache/mondo-archive"); 1256 1240 1257 1241 // paranoid_system ("mkdir -p /var/cache/mondo-archive 2> /dev/null"); 1258 1242 1259 sprintf(tmp, "cp -f %s /var/cache/mondo-archive", outfile);1260 1261 1262 sprintf(tmp, "%s/NFS-DEV", bkpinfo->tmpdir);1263 write_one_liner_data_file(tmp, nfs_dev);1264 1265 sprintf(tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir);1266 write_one_liner_data_file(tmp, nfs_client_ipaddr);1267 sprintf(tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir);1268 write_one_liner_data_file(tmp, nfs_server_ipaddr);1269 sprintf(tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir);1270 write_one_liner_data_file(tmp, bkpinfo->nfs_mount);1271 sprintf(tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir);1272 write_one_liner_data_file(tmp, bkpinfo->nfs_remote_dir);1273 log_it("Finished storing NFS configuration");1243 sprintf(tmp, "cp -f %s /var/cache/mondo-archive", outfile); 1244 run_program_and_log_output(tmp, FALSE); 1245 1246 sprintf(tmp, "%s/NFS-DEV", bkpinfo->tmpdir); 1247 write_one_liner_data_file(tmp, nfs_dev); 1248 1249 sprintf(tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir); 1250 write_one_liner_data_file(tmp, nfs_client_ipaddr); 1251 sprintf(tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir); 1252 write_one_liner_data_file(tmp, nfs_server_ipaddr); 1253 sprintf(tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir); 1254 write_one_liner_data_file(tmp, bkpinfo->nfs_mount); 1255 sprintf(tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir); 1256 write_one_liner_data_file(tmp, bkpinfo->nfs_remote_dir); 1257 log_it("Finished storing NFS configuration"); 1274 1258 } 1275 1259 … … 1296 1280 */ 1297 1281 void 1298 estimate_noof_media_required (struct s_bkpinfo *bkpinfo, long noof_sets) 1299 { 1300 /*@ buffers ****************/ 1301 char tmp[MAX_STR_LEN]; 1302 1303 /*@ long long **************/ 1304 long long scratchLL; 1305 1306 if (bkpinfo->media_size[1]<=0 || bkpinfo->backup_media_type == nfs) 1307 { 1308 log_to_screen("Number of media required: UNKNOWN"); 1309 return; 1310 } 1311 1312 log_it ("Estimating number of media required..."); 1313 scratchLL = (long long)(noof_sets) * (long long)(bkpinfo->optimal_set_size) 1314 + (long long)(size_of_all_biggiefiles_K (bkpinfo)); 1315 scratchLL = (scratchLL / 1024) / bkpinfo->media_size[1]; 1316 scratchLL++; 1317 if (bkpinfo->use_lzo) 1318 { 1319 scratchLL = (scratchLL * 2) / 3; 1320 } 1321 else 1322 { 1323 scratchLL = scratchLL / 2; 1324 } 1325 if (!scratchLL) 1326 { 1327 scratchLL++; 1328 } 1329 if (scratchLL <= 1) 1330 { 1331 sprintf (tmp, 1332 "Your backup will probably occupy a single CD/tape/ISO. Maybe two."); 1333 } 1334 else if (scratchLL > 4) 1335 { 1336 sprintf(tmp, "Your backup will occupy one meeeeellion media! (maybe %s)", 1337 number_to_text ((int) (scratchLL + 1))); 1338 } 1339 else 1340 { 1341 sprintf (tmp, "Your backup will occupy approximately %s media.", 1342 number_to_text ((int) (scratchLL + 1))); 1343 } 1344 if (!bkpinfo->image_devs[0] && (scratchLL<50)) 1345 { 1346 log_to_screen (tmp); 1347 } 1282 estimate_noof_media_required(struct s_bkpinfo *bkpinfo, long noof_sets) 1283 { 1284 /*@ buffers *************** */ 1285 char tmp[MAX_STR_LEN]; 1286 1287 /*@ long long ************* */ 1288 long long scratchLL; 1289 1290 if (bkpinfo->media_size[1] <= 0 || bkpinfo->backup_media_type == nfs) { 1291 log_to_screen("Number of media required: UNKNOWN"); 1292 return; 1293 } 1294 1295 log_it("Estimating number of media required..."); 1296 scratchLL = 1297 (long long) (noof_sets) * (long long) (bkpinfo->optimal_set_size) 1298 + (long long) (size_of_all_biggiefiles_K(bkpinfo)); 1299 scratchLL = (scratchLL / 1024) / bkpinfo->media_size[1]; 1300 scratchLL++; 1301 if (bkpinfo->use_lzo) { 1302 scratchLL = (scratchLL * 2) / 3; 1303 } else { 1304 scratchLL = scratchLL / 2; 1305 } 1306 if (!scratchLL) { 1307 scratchLL++; 1308 } 1309 if (scratchLL <= 1) { 1310 sprintf(tmp, 1311 "Your backup will probably occupy a single CD/tape/ISO. Maybe two."); 1312 } else if (scratchLL > 4) { 1313 sprintf(tmp, 1314 "Your backup will occupy one meeeeellion media! (maybe %s)", 1315 number_to_text((int) (scratchLL + 1))); 1316 } else { 1317 sprintf(tmp, "Your backup will occupy approximately %s media.", 1318 number_to_text((int) (scratchLL + 1))); 1319 } 1320 if (!bkpinfo->image_devs[0] && (scratchLL < 50)) { 1321 log_to_screen(tmp); 1322 } 1348 1323 } 1349 1324 … … 1356 1331 * @note The returned string points to static storage that will be overwritten with each call. 1357 1332 */ 1358 char*sz_last_suffix(char*instr) 1359 { 1360 static char outstr[MAX_STR_LEN]; 1361 char *p; 1362 1363 p = strrchr(instr,'.'); 1364 if (!p) 1365 { 1366 outstr[0]='\0'; 1367 } 1368 else 1369 { 1370 strcpy(outstr, p); 1371 } 1372 return(outstr); 1333 char *sz_last_suffix(char *instr) 1334 { 1335 static char outstr[MAX_STR_LEN]; 1336 char *p; 1337 1338 p = strrchr(instr, '.'); 1339 if (!p) { 1340 outstr[0] = '\0'; 1341 } else { 1342 strcpy(outstr, p); 1343 } 1344 return (outstr); 1373 1345 } 1374 1346 … … 1380 1352 * @return TRUE if it's compressed, FALSE if not. 1381 1353 */ 1382 bool is_this_file_compressed(char*filename) 1383 { 1384 char do_not_compress_these[MAX_STR_LEN]; 1385 char tmp[MAX_STR_LEN]; 1386 char *p; 1387 1388 sprintf(tmp, "%s/do-not-compress-these", g_mondo_home); 1389 if (!does_file_exist(tmp)) { return(FALSE); } 1390 strcpy(do_not_compress_these, last_line_of_file(tmp)); 1391 for(p=do_not_compress_these; p!=NULL; p++) 1392 { 1393 strcpy(tmp, p); 1394 if (strchr(tmp, ' ')) { *(strchr(tmp, ' ')) ='\0'; } 1395 if (!strcmp(sz_last_suffix(filename), tmp)) 1396 { /*printf("MATCH\n");*/ return(TRUE); } 1397 if (!(p = strchr(p, ' '))) { break; } 1398 } 1399 return(FALSE); 1400 } 1401 1402 1403 1404 int mode_of_file(char*fname) 1405 { 1406 struct stat buf; 1407 1408 if (lstat(fname, &buf)) 1409 { return(-1); } // error 1410 else 1411 { return(buf.st_mode); } 1354 bool is_this_file_compressed(char *filename) 1355 { 1356 char do_not_compress_these[MAX_STR_LEN]; 1357 char tmp[MAX_STR_LEN]; 1358 char *p; 1359 1360 sprintf(tmp, "%s/do-not-compress-these", g_mondo_home); 1361 if (!does_file_exist(tmp)) { 1362 return (FALSE); 1363 } 1364 strcpy(do_not_compress_these, last_line_of_file(tmp)); 1365 for (p = do_not_compress_these; p != NULL; p++) { 1366 strcpy(tmp, p); 1367 if (strchr(tmp, ' ')) { 1368 *(strchr(tmp, ' ')) = '\0'; 1369 } 1370 if (!strcmp(sz_last_suffix(filename), tmp)) { /*printf("MATCH\n"); */ 1371 return (TRUE); 1372 } 1373 if (!(p = strchr(p, ' '))) { 1374 break; 1375 } 1376 } 1377 return (FALSE); 1378 } 1379 1380 1381 1382 int mode_of_file(char *fname) 1383 { 1384 struct stat buf; 1385 1386 if (lstat(fname, &buf)) { 1387 return (-1); 1388 } // error 1389 else { 1390 return (buf.st_mode); 1391 } 1412 1392 } 1413 1393 … … 1420 1400 * @return 0 for success, 1 for failure. 1421 1401 */ 1422 int make_grub_install_scriptlet(char*outfile) 1423 { 1424 FILE*fout; 1425 char *tmp; 1426 int retval=0; 1427 1428 malloc_string(tmp); 1429 if ((fout = fopen( outfile, "w"))) 1430 { 1431 fprintf(fout, "#!/bin/sh\n\nmount /boot > /dev/null 2> /dev/null\ngrub-install $@\nres=$?\nsync;sync;sync\nexit $res\n"); 1432 paranoid_fclose(fout); 1433 log_msg(2, "Created %s", outfile); 1434 sprintf(tmp, "chmod +x %s", outfile); 1435 paranoid_system(tmp); 1436 retval=0; 1437 } 1438 else 1439 { 1440 retval=1; 1441 } 1442 paranoid_free(tmp); 1443 return(retval); 1402 int make_grub_install_scriptlet(char *outfile) 1403 { 1404 FILE *fout; 1405 char *tmp; 1406 int retval = 0; 1407 1408 malloc_string(tmp); 1409 if ((fout = fopen(outfile, "w"))) { 1410 fprintf(fout, 1411 "#!/bin/sh\n\nmount /boot > /dev/null 2> /dev/null\ngrub-install $@\nres=$?\nsync;sync;sync\nexit $res\n"); 1412 paranoid_fclose(fout); 1413 log_msg(2, "Created %s", outfile); 1414 sprintf(tmp, "chmod +x %s", outfile); 1415 paranoid_system(tmp); 1416 retval = 0; 1417 } else { 1418 retval = 1; 1419 } 1420 paranoid_free(tmp); 1421 return (retval); 1444 1422 } 1445 1423 -
trunk/mondo/mondo/common/libmondo-files.h
r30 r59 1 1 /* libmondo-files.h 2 * $Id : libmondo-files.h,v 1.3 2004/06/10 15:29:12 hugo Exp$2 * $Id$ 3 3 */ 4 4 … … 6 6 7 7 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); 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, 23 char *comppath); 24 int make_hole_for_file(char *outfile_fname); 25 void make_list_of_files_to_ignore(char *ignorefiles_fname, 26 char *filelist_fname, 27 char *cklist_fname); 28 long noof_lines_that_match_wildcard(char *filelist_fname, char *wildcard); 29 void register_pid(pid_t pid, char *name_str); 30 long size_of_all_biggiefiles_K(struct s_bkpinfo *bkpinfo); 31 long long space_occupied_by_cd(char *mountpt); 32 int whine_if_not_found(char *fname); 33 int write_one_liner_data_file(char *fname, char *contents); 32 34 33 void copy_mondo_and_mindi_stuff_to_scratchdir 34 void store_nfs_config 35 void estimate_noof_media_required 36 bool is_this_file_compressed (char*);35 void copy_mondo_and_mindi_stuff_to_scratchdir(struct s_bkpinfo *bkpinfo); 36 void store_nfs_config(struct s_bkpinfo *bkpinfo); 37 void estimate_noof_media_required(struct s_bkpinfo *bkpinfo, long); 38 bool is_this_file_compressed(char *); 37 39 38 40 … … 43 45 44 46 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);47 int make_hole_for_dir(char *outdir_fname); 48 long size_of_partition_in_mountlist_K(char *tmpdir, char *dev); 49 int make_grub_install_scriptlet(char *outfile); 48 50 49 int read_one_liner_data_file 50 int mode_of_file(char *fname);51 int read_one_liner_data_file(char *fname, char *contents); 52 int mode_of_file(char *fname); -
trunk/mondo/mondo/common/libmondo-fork-EXT.h
r30 r59 1 1 /* libmondo-fork-EXT.h */ 2 2 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 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, 5 char *what_i_am_doing); 6 extern int run_program_and_log_output(char *program, int); 7 extern 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); 11 extern int run_external_binary_with_percentage_indicator_OLD(char *tt, 12 char *cmd); 13 extern int run_external_binary_with_percentage_indicator_NEW(char *tt, 14 char *cmd); 15 extern int copy_from_src_to_dest(FILE *, FILE *, char); 16 extern int feed_into_partimage(char *input_device, char *output_fname); 17 extern int feed_outfrom_partimage(char *output_device, char *input_fifo); -
trunk/mondo/mondo/common/libmondo-fork.c
r30 r59 1 1 /* libmondo-fork.c 2 $Id : libmondo-fork.c,v 1.3 2004/06/21 20:20:36 hugo Exp$2 $Id$ 3 3 4 4 - subroutines for handling forking/pthreads/etc. … … 109 109 110 110 /*@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$"; 112 112 113 113 extern char *g_tmpfs_mountpt; 114 114 extern t_bkptype g_backup_media_type; 115 115 extern bool g_text_mode; 116 pid_t g_buffer_pid =0;116 pid_t g_buffer_pid = 0; 117 117 118 118 … … 123 123 * @note The returned value points to static storage that will be overwritten with each call. 124 124 */ 125 char * 126 call_program_and_get_last_line_of_output (char *call) 125 char *call_program_and_get_last_line_of_output(char *call) 127 126 { 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); 161 155 } 162 156 … … 186 180 */ 187 181 int 188 eval_call_to_make_ISO 189 190 182 eval_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) 191 185 { 192 186 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; 200 195 201 196 /*@*********** End Variables ***************************************/ 202 197 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); 245 249 #ifndef _XWIN 246 if (!g_text_mode) { newtSuspend(); } 250 if (!g_text_mode) { 251 newtSuspend(); 252 } 247 253 #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); 262 269 // 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); 273 282 /* 274 283 if (bkpinfo->backup_media_type == dvd && !bkpinfo->please_dont_eject_when_restoring) … … 278 287 } 279 288 */ 280 289 return (retval); 281 290 } 282 291 … … 290 299 * @return The exit code of @p program (depends on the command, but 0 almost always indicates success). 291 300 */ 292 int 293 run_program_and_log_output (char *program, int debug_level) 301 int run_program_and_log_output(char *program, int debug_level) 294 302 { 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 } 320 327 // if (debug_level == TRUE) { debug_level=5; } 321 328 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")) 366 368 { 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 } 391 403 // else 392 404 // { log_msg (0, "-------------------------------ran w/ res=%d------------------------------", res); } 393 405 return (res); 394 406 } 395 407 … … 404 416 * @see log_to_screen 405 417 */ 406 int 407 run_program_and_log_to_screen (char *basic_call, char *what_i_am_doing) 418 int run_program_and_log_to_screen(char *basic_call, char *what_i_am_doing) 408 419 { 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 } 449 457 #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 } 459 468 #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 } 466 474 #endif 467 paranoid_pclose(fin);468 469 close_evalcall_form();470 unlink(lockfile);471 475 paranoid_pclose(fin); 476 retval += res; 477 close_evalcall_form(); 478 unlink(lockfile); 479 return (retval); 472 480 } 473 481 … … 484 492 * @return NULL to pthread_join. 485 493 */ 486 void *call_partimage_in_bkgd(void *xfb)494 void *call_partimage_in_bkgd(void *xfb) 487 495 { 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); 503 513 } 504 514 … … 525 535 #define NO_MORE_SUBVOLS "On-second-hand,momma-bounced-on-old-man,-and-so-we-moved-to-Shaolin-Land." 526 536 527 int copy_from_src_to_dest(FILE *f_orig, FILE*f_archived, char direction)537 int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived, char direction) 528 538 { 529 539 // if dir=='w' then copy from orig to archived 530 540 // 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 } 590 627 591 628 // log_msg(4, "Written %ld of %ld bytes", bytes_written_out, bytes_read_in); 592 629 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); 610 646 // if (bytes_read_in!=128+64) { fatal_error("Can't read the terminating block"); } 611 612 613 // 614 615 616 617 618 619 620 621 622 623 624 625 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); 627 663 } 628 664 … … 634 670 * @return 0 for success, nonzero for failure. 635 671 */ 636 int dynamically_create_pipes_and_copy_from_them_to_output_file(char*input_device, char*output_fname) 672 int dynamically_create_pipes_and_copy_from_them_to_output_file(char 673 *input_device, 674 char 675 *output_fname) 637 676 { 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 } 694 751 // 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."); 721 786 722 787 // if (!lstat(sz_wait_for_this_file, &statbuf)) 723 788 // { log_msg(3, "WARNING! %s was not processed.", sz_wait_for_this_file); } 724 725 726 727 728 729 730 731 732 733 734 735 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); 737 802 } 738 803 … … 744 809 * @return 0 for success, nonzero for failure. 745 810 */ 746 int feed_into_partimage(char *input_device, char*output_fname)811 int feed_into_partimage(char *input_device, char *output_fname) 747 812 { 748 813 // 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); 755 826 } 756 827 … … 759 830 760 831 761 int 762 run_external_binary_with_percentage_indicator_OLD (char *tt, char *cmd) 832 int run_external_binary_with_percentage_indicator_OLD(char *tt, char *cmd) 763 833 { 764 834 765 /*@ int *************************************************************** */766 835 /*@ int *************************************************************** */ 836 int res = 0; 767 837 int percentage = 0; 768 838 int maxpc = 0; … … 770 840 int last_pcno = 0; 771 841 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; 799 868 // 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 } 818 884 // 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); 826 895 } 827 896 … … 829 898 830 899 831 void *run_prog_in_bkgd_then_exit(void*info)900 void *run_prog_in_bkgd_then_exit(void *info) 832 901 { 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)); 844 915 } 845 916 … … 847 918 848 919 849 int 850 run_external_binary_with_percentage_indicator_NEW (char*tt, char*cmd) 920 int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd) 851 921 { 852 922 853 /*@ int *************************************************************** */854 923 /*@ int *************************************************************** */ 924 int res = 0; 855 925 int percentage = 0; 856 926 int maxpc = 100; 857 927 int pcno = 0; 858 928 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); 916 988 } 917 989 … … 928 1000 * @bug Probably unnecessary, as the partimage is just a sparse file. We could use @c dd to restore it. 929 1001 */ 930 int feed_outfrom_partimage(char *output_device, char*input_fifo)1002 int feed_outfrom_partimage(char *output_device, char *input_fifo) 931 1003 { 932 1004 // RESTORE 933 1005 char *tmp; 934 1006 // char *command; 935 936 937 938 939 940 941 942 943 944 int fifo_number=0;945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 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); 961 1033 /* I don't trust g_tmpfs_mountpt 962 1034 if (g_tmpfs_mountpt[0]) … … 967 1039 { 968 1040 */ 969 1041 strcpy(tmpstub, "/tmp"); 970 1042 // } 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); 1033 1128 // system("sync"); 1034 usleep(1000L*100L);1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 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); 1058 1153 } 1059 -
trunk/mondo/mondo/common/libmondo-fork.h
r30 r59 1 1 /* libmondo-fork.h 2 * $Id : libmondo-fork.h,v 1.2 2004/06/10 15:29:12 hugo Exp$2 * $Id$ 3 3 */ 4 4 5 5 6 6 7 char *call_program_and_get_last_line_of_output 8 int run_program_and_log_to_screen 9 int run_program_and_log_output 10 int eval_call_to_make_ISO 11 12 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); 13 13 14 int run_external_binary_with_percentage_indicator_OLD 15 int run_external_binary_with_percentage_indicator_NEW 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);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); -
trunk/mondo/mondo/common/libmondo-gui-EXT.h
r30 r59 2 2 3 3 #ifdef _XWIN 4 4 #include "X-specific-EXT.h" 5 5 #else 6 6 #include "newt-specific-EXT.h" 7 7 #endif 8 9 10 11 12 -
trunk/mondo/mondo/common/libmondo-gui.h
r30 r59 1 1 /* libmondo-gui.h 2 * $Id : libmondo-gui.h,v 1.2 2004/06/10 15:29:12 hugo Exp$2 * $Id$ 3 3 */ 4 4 5 5 #ifdef _XWIN 6 6 #include "X-specific.h" 7 7 #else 8 8 #include "newt-specific.h" 9 9 #endif 10 11 12 13 14 15 -
trunk/mondo/mondo/common/libmondo-mountlist-EXT.h
r30 r59 1 1 /* libmondo-mountlist-EXT.h */ 2 2 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); 3 extern int evaluate_drive_within_mountlist(struct mountlist_itself 4 *mountlist, char *drive, 5 char *flaws_str); 6 extern int evaluate_mountlist(struct mountlist_itself *mountlist, 7 char *flaws_str_A, char *flaws_str_B, 8 char *flaws_str_C); 9 extern int find_device_in_mountlist(struct mountlist_itself *mountlist, 10 char *device); 11 extern int look_for_duplicate_mountpoints(struct mountlist_itself 12 *mountlist, char *flaws_str); 13 extern int look_for_weird_formats(struct mountlist_itself *mountlist, 14 char *flaws_str); 15 extern int make_list_of_drives_in_mountlist(struct mountlist_itself *, 16 struct list_of_disks *); 17 extern long long size_of_specific_device_in_mountlist(struct 18 mountlist_itself 19 *mountlist, 20 char *device); 12 21 13 22 14 23 15 24 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); 25 extern int load_mountlist(struct mountlist_itself *mountlist, char *fname); 26 extern void sort_mountlist_by_device(struct mountlist_itself *mountlist); 27 extern int save_mountlist_to_disk(struct mountlist_itself *mountlist, 28 char *fname); 29 extern void sort_mountlist_by_mountpoint(struct mountlist_itself 30 *mountlist, bool reverse); 31 extern void sort_mountlist_by_device(struct mountlist_itself *mountlist); 32 extern void swap_mountlist_entries(struct mountlist_itself *mountlist, 33 int a, int b); -
trunk/mondo/mondo/common/libmondo-mountlist.c
r49 r59 122 122 if (device_copies > 1) { 123 123 asprintf(&tmp, " %s %s's.", number_to_text(device_copies), 124 device);124 device); 125 125 if (!strstr(flaws_str, tmp)) { 126 126 log_it(tmp); … … 184 184 return ++res; // fatal error 185 185 } 186 187 186 // BERLIOS : useless ? asprintf(&mountpoint, mountlist->el[pos].mountpoint); 188 187 if (pos > 0 && !npos) { … … 199 198 || (curr_part_no <= 4 && prev_part_no > 0)) { 200 199 asprintf(&tmp, " Gap between %ss%d and %d.", drive, 201 prev_part_no, curr_part_no);200 prev_part_no, curr_part_no); 202 201 log_it(tmp); 203 202 strcat(flaws_str, tmp); … … 226 225 if (device_copies > 1) { 227 226 asprintf(&tmp, " %s %s's.", number_to_text(device_copies), 228 device);227 device); 229 228 if (!strstr(flaws_str, tmp)) { 230 229 log_it(tmp); … … 268 267 /* Check subpartitions */ 269 268 for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) { 270 asprintf(&device, "%ss%d%c", drive, curr_part_no, cur_sp_no); 269 asprintf(&device, "%ss%d%c", drive, curr_part_no, 270 cur_sp_no); 271 271 pos = find_device_in_mountlist(mountlist, device); 272 272 if (pos < 0) { … … 276 276 /* is it too big? */ 277 277 if (curr_part_no > 'h') { 278 asprintf(&tmp, " Can only have up to 'h' in disklabel."); 278 asprintf(&tmp, 279 " Can only have up to 'h' in disklabel."); 279 280 log_it(tmp); 280 281 strcat(flaws_str, tmp); … … 291 292 if (device_copies > 1) { 292 293 asprintf(&tmp, " %s %s's.", 293 number_to_text(device_copies), device);294 number_to_text(device_copies), device); 294 295 if (!strstr(flaws_str, tmp)) { 295 296 log_it(tmp); … … 345 346 { 346 347 asprintf(&tmp, " %ld MB over-allocated on %s.", 347 amount_allocated - physical_drive_size, drive);348 amount_allocated - physical_drive_size, drive); 348 349 log_it(tmp); 349 350 strcat(flaws_str, tmp); … … 352 353 } else if (amount_allocated < physical_drive_size - 1) { /* NOT AN ERROR, JUST A WARNING :-) */ 353 354 asprintf(&tmp, " %ld MB unallocated on %s.", 354 physical_drive_size - amount_allocated, drive);355 physical_drive_size - amount_allocated, drive); 355 356 log_it(tmp); 356 357 strcat(flaws_str, tmp); 357 358 paranoid_free(tmp); 358 359 } … … 407 408 log_msg(1, tmp); 408 409 paranoid_free(tmp); 409 return (FALSE);410 return (FALSE); 410 411 } else { 411 412 asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size); … … 439 440 || (curr_part_no <= 4 && prev_part_no > 0)) { 440 441 asprintf(&tmp, " Gap between %s%d and %d.", drive, 441 prev_part_no, curr_part_no);442 prev_part_no, curr_part_no); 442 443 log_it(tmp); 443 444 strcat(flaws_str, tmp); … … 466 467 if (device_copies > 1) { 467 468 asprintf(&tmp, " %s %s's.", number_to_text(device_copies), 468 device);469 device); 469 470 if (!strstr(flaws_str, tmp)) { 470 471 log_it(tmp); … … 512 513 if (amount_allocated > physical_drive_size + 1) { 513 514 asprintf(&tmp, " %ld MB over-allocated on %s.", 514 amount_allocated - physical_drive_size, drive);515 amount_allocated - physical_drive_size, drive); 515 516 log_it(tmp); 516 517 strcat(flaws_str, tmp); … … 519 520 } else if (amount_allocated < physical_drive_size - 1) { /* NOT AN ERROR, JUST A WARNING :-) */ 520 521 asprintf(&tmp, " %ld MB unallocated on %s.", 521 physical_drive_size - amount_allocated, drive);522 physical_drive_size - amount_allocated, drive); 522 523 log_it(tmp); 523 524 strcat(flaws_str, tmp); … … 578 579 DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE)) { 579 580 asprintf(&tmp, " Not evaluating %s (I don't know how yet)", 580 drivelist->el[i].device);581 drivelist->el[i].device); 581 582 log_it(tmp); 582 583 } else { … … 668 669 && strcmp(curr_mountpoint, "raid")) { 669 670 asprintf(&tmp, " %s %s's.", number_to_text(copies), 670 curr_mountpoint);671 curr_mountpoint); 671 672 strcat(flaws_str, tmp); 672 673 log_it(tmp); … … 707 708 && strcmp(mountlist->el[i].mountpoint, "image") != 0) { 708 709 asprintf(&tmp, " %s has unknown format.", 709 mountlist->el[i].device);710 mountlist->el[i].device); 710 711 log_it(tmp); 711 712 strcat(flaws_str, tmp); … … 760 761 if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) { 761 762 asprintf(&tmp, 762 "Not putting %s in list of drives: it's a virtual drive",763 drive);763 "Not putting %s in list of drives: it's a virtual drive", 764 drive); 764 765 log_msg(8, tmp); 765 766 paranoid_free(tmp); … … 770 771 if (size == 0) { 771 772 asprintf(&tmp, 772 "Not putting %s in list of drives: it has zero size (maybe an LVM volume)",773 drive);773 "Not putting %s in list of drives: it has zero size (maybe an LVM volume)", 774 drive); 774 775 log_msg(8, tmp); 775 776 paranoid_free(tmp); … … 789 790 790 791 asprintf(&tmp, 791 "Putting %s with size %lli in list of drives",792 drive, size);792 "Putting %s with size %lli in list of drives", 793 drive, size); 793 794 log_msg(8, tmp); 794 795 paranoid_free(tmp); … … 820 821 */ 821 822 void make_list_of_unallocated_raid_partitions(struct mountlist_itself 822 *output_list, 823 struct mountlist_itself 824 *mountlist, 825 struct raidlist_itself 823 *output_list, struct mountlist_itself 824 *mountlist, struct raidlist_itself 826 825 *raidlist) 827 826 { … … 853 852 sizeof(struct mountlist_line)); 854 853 asprintf(&tmp, 855 "%s is available; user may choose to add it to raid device",856 output_list->el[items - 1].device);854 "%s is available; user may choose to add it to raid device", 855 output_list->el[items - 1].device); 857 856 log_it(tmp); 858 857 paranoid_free(tmp); … … 972 971 strcat(mountlist->el[items].device, "_dup"); 973 972 asprintf(&tmp, 974 "Duplicate entry in mountlist - renaming to %s",975 mountlist->el[items].device);973 "Duplicate entry in mountlist - renaming to %s", 974 mountlist->el[items].device); 976 975 log_it(tmp); 977 976 paranoid_free(tmp); … … 993 992 994 993 asprintf(&tmp, 995 "%s %s %s %lld %s", 996 mountlist->el[items].device, 997 mountlist->el[items].mountpoint, 998 mountlist->el[items].format, 999 mountlist->el[items].size, mountlist->el[items].label); 994 "%s %s %s %lld %s", 995 mountlist->el[items].device, 996 mountlist->el[items].mountpoint, 997 mountlist->el[items].format, 998 mountlist->el[items].size, 999 mountlist->el[items].label); 1000 1000 1001 1001 log_it(tmp); -
trunk/mondo/mondo/common/libmondo-mountlist.h
r30 r59 1 1 /* libmondo-mountlist.h 2 * $Id : libmondo-mountlist.h,v 1.2 2004/06/10 15:29:12 hugo Exp$2 * $Id$ 3 3 */ 4 4 5 5 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); 6 int evaluate_drive_within_mountlist(struct mountlist_itself *mountlist, 7 char *drive, char *flaws_str); 8 int evaluate_mountlist(struct mountlist_itself *mountlist, 9 char *flaws_str_A, char *flaws_str_B, 10 char *flaws_str_C); 11 int find_device_in_mountlist(struct mountlist_itself *mountlist, 12 char *device); 13 int look_for_duplicate_mountpoints(struct mountlist_itself *mountlist, 14 char *flaws_str); 15 int look_for_weird_formats(struct mountlist_itself *mountlist, 16 char *flaws_str); 17 int make_list_of_drives_in_mountlist(struct mountlist_itself *, 18 struct list_of_disks *); 19 long long size_of_specific_device_in_mountlist(struct mountlist_itself 20 *mountlist, char *device); 15 21 16 22 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 23 int load_mountlist(struct mountlist_itself *mountlist, char *fname); 24 void sort_mountlist_by_device(struct mountlist_itself *mountlist); 25 int save_mountlist_to_disk(struct mountlist_itself *mountlist, 26 char *fname); 27 void sort_mountlist_by_mountpoint(struct mountlist_itself *mountlist, 28 bool reverse); 29 void sort_mountlist_by_device(struct mountlist_itself *mountlist); 30 void swap_mountlist_entries(struct mountlist_itself *mountlist, int a, 31 int b); -
trunk/mondo/mondo/common/libmondo-raid-EXT.h
r30 r59 5 5 #endif 6 6 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); 7 extern bool is_this_raid_personality_registered(int raidno); 8 extern int which_raid_device_is_using_this_partition(struct raidlist_itself 9 *raidlist, 10 char *device); 11 extern void write_variableINT_to_raid_var_line(struct raid_device_record 12 *raidrec, int lino, 13 char *label, int value); 12 14 13 extern int where_in_drivelist_is_drive (struct list_of_disks *disklist, char *device); 15 extern int where_in_drivelist_is_drive(struct list_of_disks *disklist, 16 char *device); 14 17 15 18 16 19 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); 20 extern int load_raidtab_into_raidlist(struct raidlist_itself *, char *); 21 extern int save_raidlist_to_raidtab(struct raidlist_itself *, char *); 22 extern void process_raidtab_line(FILE *, struct raid_device_record *, 23 char *, char *); 24 extern int save_raidlist_to_raidtab(struct raidlist_itself *raidlist, 25 char *fname); 26 extern void save_raidrec_to_file(struct raid_device_record *raidrec, 27 FILE * fout); 22 28 23 extern void 24 save_disklist_to_file(char *listname, 25 struct list_of_disks *disklist, 26 FILE *fout); 29 extern void 30 save_disklist_to_file(char *listname, 31 struct list_of_disks *disklist, FILE * fout); 27 32 28 33 29 34 #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); 35 extern void add_disk_to_raid_device(struct vinum_plex *p, 36 char *device_to_add); 37 extern void add_plex_to_volume(struct vinum_volume *v, int raidlevel, 38 int stripesize); 39 extern void add_disk_to_raid_device(struct vinum_plex *p, 40 char *device_to_add); 33 41 extern 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); 42 extern bool get_option_state(int argc, char **argv, char *option); 43 extern char **get_option_vals(int argc, char **argv, char *option, 44 int nval); 45 extern char *get_option_val(int argc, char **argv, char *option); 46 extern char **get_next_vinum_conf_line(FILE * f, int *argc); 47 extern void add_plex_to_volume(struct vinum_volume *v, int raidlevel, 48 int stripesize); 39 49 #undef raid_device_record 40 50 #else 41 extern void add_disk_to_raid_device(struct list_of_disks *disklist, char*device_to_add, int index); 51 extern void add_disk_to_raid_device(struct list_of_disks *disklist, 52 char *device_to_add, int index); 42 53 #endif 43 54 44 extern int create_raidtab_from_mdstat(char *,char*);45 extern int read_mdstat(struct s_mdstat *mdstat, char *mdstat_file);55 extern int create_raidtab_from_mdstat(char *, char *); 56 extern int read_mdstat(struct s_mdstat *mdstat, char *mdstat_file); 46 57 47 extern int create_raidtab_from_mdstat(char*raidtab_fname, char *mdstat_fname); 58 extern int create_raidtab_from_mdstat(char *raidtab_fname, 59 char *mdstat_fname); -
trunk/mondo/mondo/common/libmondo-raid.h
r30 r59 1 1 /* libmondo-raid.h 2 * $Id : libmondo-raid.h,v 1.2 2004/06/10 15:29:12 hugo Exp$2 * $Id$ 3 3 */ 4 4 … … 7 7 #endif 8 8 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); 9 bool is_this_raid_personality_registered(int raidno); 10 int which_raid_device_is_using_this_partition(struct raidlist_itself 11 *raidlist, 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, 15 char *device); 15 16 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); 17 int load_raidtab_into_raidlist(struct raidlist_itself *, char *); 18 int save_raidlist_to_raidtab(struct raidlist_itself *, char *); 19 void process_raidtab_line(FILE *, struct raid_device_record *, char *, 20 char *); 21 int save_raidlist_to_raidtab(struct raidlist_itself *raidlist, 22 char *fname); 23 void save_raidrec_to_file(struct raid_device_record *raidrec, FILE * fout); 24 void 25 save_disklist_to_file(char *listname, 26 struct list_of_disks *disklist, FILE * fout); 25 27 #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); 28 void add_disk_to_raid_device(struct vinum_plex *p, char *device_to_add); 29 void add_plex_to_volume(struct vinum_volume *v, int raidlevel, 30 int stripesize); 31 void add_disk_to_raid_device(struct vinum_plex *p, char *device_to_add); 29 32 long 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); 33 bool get_option_state(int argc, char **argv, char *option); 34 char **get_option_vals(int argc, char **argv, char *option, int nval); 35 char *get_option_val(int argc, char **argv, char *option); 36 char **get_next_vinum_conf_line(FILE * f, int *argc); 37 void add_plex_to_volume(struct vinum_volume *v, int raidlevel, 38 int stripesize); 35 39 #undef raid_device_record 36 40 #else 37 void add_disk_to_raid_device(struct list_of_disks *disklist, char*device_to_add, int index); 41 void add_disk_to_raid_device(struct list_of_disks *disklist, 42 char *device_to_add, int index); 38 43 #endif 39 44 40 45 41 int create_raidtab_from_mdstat(char *,char*);42 int read_mdstat(struct s_mdstat *mdstat, char *mdstat_file);46 int create_raidtab_from_mdstat(char *, char *); 47 int read_mdstat(struct s_mdstat *mdstat, char *mdstat_file); 43 48 44 int create_raidtab_from_mdstat(char*raidtab_fname, char *mdstat_fname); 45 49 int create_raidtab_from_mdstat(char *raidtab_fname, char *mdstat_fname); -
trunk/mondo/mondo/common/libmondo-stream-EXT.h
r30 r59 3 3 4 4 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 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, 11 char *latest_fname); 12 extern int openin_cdstream(struct s_bkpinfo *bkpinfo); 13 extern int openin_tape(struct s_bkpinfo *bkpinfo); 14 extern int openout_cdstream(char *cddev, int speed); 15 extern int openout_tape(char *tapedev, long internal_tape_block_size); 16 extern int read_file_from_stream_to_file(struct s_bkpinfo *bkpinfo, 17 char *outfile, long long size); 18 extern int read_file_from_stream_to_stream(struct s_bkpinfo *bkpinfo, 19 FILE * fout, long long size); 20 extern int read_file_from_stream_FULL(struct s_bkpinfo *bkpinfo, 21 char *outfname, FILE * foutstream, 22 long long orig_size); 23 extern int read_header_block_from_stream(long long *plen, char *filename, 24 int *pcontrol_char); 25 extern int register_in_tape_catalog(t_archtype type, int number, long aux, 26 char *fn); 27 extern bool should_we_write_to_next_tape(long mediasize, 28 long long 29 length_of_incoming_file); 30 extern int skip_incoming_files_until_we_find_this_one(char 31 *the_file_I_was_reading); 32 extern int start_to_read_from_next_tape(struct s_bkpinfo *bkpinfo); 33 extern int start_to_write_to_next_tape(struct s_bkpinfo *bkpinfo); 34 extern int write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo); 35 extern int write_data_disks_to_stream(char *fname); 36 extern int write_file_to_stream_from_file(struct s_bkpinfo *bkpinfo, 37 char *infile); 38 extern int write_header_block_to_stream(long long length_of_incoming_file, 39 char *filename, int control_char); 40 extern void wrong_marker(int should_be, int it_is); 41 extern int closein_cdstream(struct s_bkpinfo *bkpinfo); 42 extern 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); 46 extern int write_EXAT_files_to_tape(struct s_bkpinfo *bkpinfo, 47 char *xattr_fname, char *acl_fname); -
trunk/mondo/mondo/common/libmondo-stream.c
r58 r59 1636 1636 } 1637 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; 1638 g_tape_posK += fwrite(datablock, 1, /*bytes_to_read */ 1639 (size_t) TAPE_BLOCK_SIZE, 1640 g_tape_stream) / 1024; 1642 1641 if (g_sigpipe) { 1643 1642 iamhere("Sigpipe occurred recently. I'll start a new tape."); -
trunk/mondo/mondo/common/libmondo-stream.h
r58 r59 5 5 6 6 7 int closein_tape 8 int closeout_tape 9 int find_tape_device_and_size (char*dev, char*siz);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); 10 10 void insist_on_this_tape_number(int tapeno); 11 void log_tape_pos 11 void log_tape_pos(void); 12 12 int 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); 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, 26 char *fn); 27 bool should_we_write_to_next_tape(long mediasize, 28 long long length_of_incoming_file); 29 int skip_incoming_files_until_we_find_this_one(char 30 *the_file_I_was_reading); 31 int start_to_read_from_next_tape(struct s_bkpinfo *bkpinfo); 32 int start_to_write_to_next_tape(struct s_bkpinfo *bkpinfo); 33 int write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo); 34 int write_data_disks_to_stream(char *fname); 35 int write_file_to_stream_from_file(struct s_bkpinfo *bkpinfo, 36 char *infile); 37 int write_header_block_to_stream(long long length_of_incoming_file, 38 char *filename, int control_char); 39 void wrong_marker(int should_be, int it_is); 40 int closein_cdstream(struct s_bkpinfo *bkpinfo); 41 int 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); 45 int write_EXAT_files_to_tape(struct s_bkpinfo *bkpinfo, char *xattr_fname, 46 char *acl_fname); -
trunk/mondo/mondo/common/libmondo-string-EXT.h
r30 r59 1 1 /* 2 * $Id : libmondo-string-EXT.h,v 1.2 2004/06/10 15:29:12 hugo Exp$2 * $Id$ 3 3 */ 4 4 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); 5 extern char *build_partition_name(char *partition, const char *drive, 6 int partno); 7 extern void center_string(char *in_out, int width); 8 extern char *commarize(char *); 9 extern char *disklist_entry_to_string(struct list_of_disks *disklist, 10 int lino); 11 extern long friendly_sizestr_to_sizelong(char *incoming); 12 extern char *leftpad_string(char *incoming, int width); 13 extern char *marker_to_string(int marker); 14 extern char *mountlist_entry_to_string(struct mountlist_itself *mountlist, 15 int lino); 16 extern char *number_of_disks_as_string(int noof_disks, char *label); 17 extern char *number_to_text(int i); 18 extern void resolve_naff_tokens(char *output, char *ip, char *value, 19 char *token); 20 extern char *slice_fname(long bigfileno, long sliceno, char *path, 21 char *s); 22 extern int special_dot_char(int i); 23 extern 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); 27 extern int strcmp_inc_numbers(char *stringA, char *stringB); 28 extern char *strip_afio_output_line(char *input); 29 extern void strip_spaces(char *in_out); 30 extern char *trim_empty_quotes(char *incoming); 31 extern char *truncate_to_drive_name(char *partition); 32 extern char *turn_raid_level_number_to_string(int raid_level); 27 33 28 34 extern void printf_silly_message(void); 29 35 30 extern int compare_two_filelist_entries(void *va,void*vb);36 extern int compare_two_filelist_entries(void *va, void *vb); 31 37 extern int severity_of_difference(char *filename, char *out_reason); 32 38 33 extern char *percent_media_full_comment 39 extern char *percent_media_full_comment(struct s_bkpinfo *bkpinfo); 34 40 35 41 36 42 extern char *media_descriptor_string(t_bkptype); 37 43 38 extern inline void turn_wildcard_chars_into_literal_chars(char *out, char*in);39 44 extern inline void turn_wildcard_chars_into_literal_chars(char *out, 45 char *in); -
trunk/mondo/mondo/common/libmondo-string.h
r30 r59 1 1 /* 2 * $Id : libmondo-string.h,v 1.2 2004/06/10 15:29:12 hugo Exp$2 * $Id$ 3 3 */ 4 4 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); 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, 13 int lino); 14 char *number_of_disks_as_string(int noof_disks, char *label); 15 char *number_to_text(int i); 16 void resolve_naff_tokens(char *output, char *ip, char *value, char *token); 17 char *slice_fname(long bigfileno, long sliceno, char *path, char *s); 18 int special_dot_char(int i); 19 bool spread_flaws_across_three_lines(char *flaws_str, char *flaws_str_A, 20 char *flaws_str_B, char *flaws_str_C, 21 int res); 22 int strcmp_inc_numbers(char *stringA, char *stringB); 23 char *strip_afio_output_line(char *input); 24 void strip_spaces(char *in_out); 25 char *trim_empty_quotes(char *incoming); 26 char *truncate_to_drive_name(char *partition); 27 char *turn_raid_level_number_to_string(int raid_level); 27 28 void printf_silly_message(void); 28 29 29 int compare_two_filelist_entries(void *va,void*vb);30 int compare_two_filelist_entries(void *va, void *vb); 30 31 int severity_of_difference(char *filename, char *out_reason); 31 32 32 char *percent_media_full_comment 33 char *percent_media_full_comment(struct s_bkpinfo *bkpinfo); 33 34 char *media_descriptor_string(t_bkptype); 34 inline void turn_wildcard_chars_into_literal_chars(char *out, char*in);35 inline void turn_wildcard_chars_into_literal_chars(char *out, char *in); -
trunk/mondo/mondo/common/libmondo-tools-EXT.h
r30 r59 2 2 3 3 extern void clean_up_KDE_desktop_if_necessary(void); 4 extern long get_time 4 extern long get_time(); 5 5 extern 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, ...); 8 extern void standard_log_debug_msg(int debug_level, const char *szFile, 9 const char *szFunction, int nLine, 10 const char *fmt, ...); 11 extern int read_cfg_var(char *config_file, char *label, char *value); 12 extern int write_cfg_var(char *config_file, char *label, char *value); 13 extern void reset_bkpinfo(struct s_bkpinfo *bkpinfo); 12 14 #ifdef __FreeBSD__ 13 extern void initialize_raidrec 15 extern void initialize_raidrec(struct vinum_volume *vv); 14 16 #else 15 extern void initialize_raidrec 17 extern void initialize_raidrec(struct raid_device_record *raidrec); 16 18 #endif 17 extern void log_trace 18 extern int some_basic_system_sanity_checks 19 extern void log_trace(char *o); 20 extern int some_basic_system_sanity_checks(); 19 21 20 22 … … 28 30 extern void remount_supermounts_if_necessary(void); 29 31 30 extern int post_param_configuration 32 extern int post_param_configuration(struct s_bkpinfo *bkpinfo); 31 33 32 34 … … 41 43 42 44 extern double get_kernel_version(); 43 extern char * 45 extern char *get_architecture(); 44 46 45 extern bool does_nonMS_partition_exist 47 extern bool does_nonMS_partition_exist(void); 46 48 47 49 … … 50 52 extern void stop_autofs_if_necessary(void); 51 53 extern void restart_autofs_if_necessary(void); 52 -
trunk/mondo/mondo/common/libmondo-tools.c
r58 r59 702 702 retval++; 703 703 } else { 704 strcpy(ip_address, inet_ntoa 705 ((struct in_addr)706 *((struct in_addr *) hent->h_addr)));704 strcpy(ip_address, inet_ntoa((struct in_addr) 705 *((struct in_addr *) hent-> 706 h_addr))); 707 707 strcat(ip_address, strchr(bkpinfo->nfs_mount, ':')); 708 708 strcpy(bkpinfo->nfs_mount, ip_address); -
trunk/mondo/mondo/common/libmondo-tools.h
r30 r59 1 1 /* libmondo-tools.h 2 * $Id: libmondo-tools.h,v 1.2 2004/06/10 15:29:12 hugo Exp$3 */2 * $Id$ 3 */ 4 4 5 5 void clean_up_KDE_desktop_if_necessary(void); 6 6 7 long get_time 7 long get_time(); 8 8 extern 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, ...); 11 void standard_log_debug_msg(int debug_level, const char *szFile, 12 const char *szFunction, int nLine, 13 const char *fmt, ...); 14 int read_cfg_var(char *config_file, char *label, char *value); 15 int write_cfg_var(char *config_file, char *label, char *value); 16 void reset_bkpinfo(struct s_bkpinfo *bkpinfo); 15 17 #ifdef __FreeBSD__ 16 void initialize_raidrec 18 void initialize_raidrec(struct vinum_volume *vv); 17 19 #else 18 void initialize_raidrec 20 void initialize_raidrec(struct raid_device_record *raidrec); 19 21 #endif 20 void log_trace 21 int some_basic_system_sanity_checks 22 void log_trace(char *o); 23 int some_basic_system_sanity_checks(); 22 24 23 25 … … 29 31 void remount_supermounts_if_necessary(void); 30 32 31 int post_param_configuration 33 int post_param_configuration(struct s_bkpinfo *bkpinfo); 32 34 33 35 34 36 int pre_param_configuration(struct s_bkpinfo *bkpinfo); 35 37 36 long free_space_on_given_partition(char *partition);38 long free_space_on_given_partition(char *partition); 37 39 38 40 … … 46 48 47 49 double get_kernel_version(); 48 char * 49 bool does_nonMS_partition_exist 50 char *get_architecture(); 51 bool does_nonMS_partition_exist(void); 50 52 void stop_magicdev_if_necessary(void); 51 53 void restart_magicdev_if_necessary(void); 52 54 void stop_autofs_if_necessary(void); 53 55 void restart_autofs_if_necessary(void); 54 55 -
trunk/mondo/mondo/common/libmondo-verify-EXT.h
r30 r59 2 2 3 3 4 extern int verify_cd_image 5 extern int verify_a_tarball 6 extern int verify_an_afioball_from_CD 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 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 *, 8 long long); 9 extern int verify_a_biggiefile_from_tape(struct s_bkpinfo *, char *, 10 long long); 11 int verify_afioballs_from_CD(struct s_bkpinfo *); 12 extern int verify_afioballs_from_tape(struct s_bkpinfo *); 13 extern int verify_biggiefiles_from_tape(struct s_bkpinfo *); 14 extern int verify_tape_backups(struct s_bkpinfo *); 15 extern char *vfy_tball_fname(struct s_bkpinfo *, char *, int); -
trunk/mondo/mondo/common/libmondo-verify.c
r49 r59 74 74 log_msg(1, "Now scanning log file for 'afio: ' stuff"); 75 75 asprintf(&command, 76 "cat %s | grep \"afio: \" | sed 's/afio: //' | grep -vx \"/dev/.*\" >> %s",77 stderr_fname, afio_found_changes);76 "cat %s | grep \"afio: \" | sed 's/afio: //' | grep -vx \"/dev/.*\" >> %s", 77 stderr_fname, afio_found_changes); 78 78 log_msg(2, command); 79 79 res = system(command); … … 85 85 log_msg(1, "Now scanning log file for 'star: ' stuff"); 86 86 asprintf(&command, 87 "cat %s | grep \"star: \" | sed 's/star: //' | grep -vx \"/dev/.*\" >> %s",88 stderr_fname, afio_found_changes);87 "cat %s | grep \"star: \" | sed 's/star: //' | grep -vx \"/dev/.*\" >> %s", 88 stderr_fname, afio_found_changes); 89 89 log_msg(2, command); 90 90 res = system(command); … … 96 96 afio_diffs = count_lines_in_file(afio_found_changes); 97 97 asprintf(&command, 98 "cat %s %s %s | sort | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s",99 ignorefiles_fname, afio_found_changes, afio_found_changes,100 changedfiles_fname);98 "cat %s %s %s | sort | uniq -c | awk '{ if ($1==\"2\") {print $2;};}' | grep -v \"incheckentry xwait()\" > %s", 99 ignorefiles_fname, afio_found_changes, afio_found_changes, 100 changedfiles_fname); 101 101 log_msg(2, command); 102 102 paranoid_system(command); … … 150 150 retval++; 151 151 asprintf(&tmp, "Warning - missing set(s) between %d and %d\n", 152 g_last_afioball_number, set_number - 1);152 g_last_afioball_number, set_number - 1); 153 153 log_to_screen(tmp); 154 154 paranoid_free(tmp); … … 156 156 } 157 157 asprintf(&tmp, "Verifying %s #%d's tarballs", 158 media_descriptor_string(bkpinfo->backup_media_type),159 g_current_media_number);158 media_descriptor_string(bkpinfo->backup_media_type), 159 g_current_media_number); 160 160 open_evalcall_form(tmp); 161 161 paranoid_free(tmp); … … 177 177 verify_an_afioball_from_CD(bkpinfo, 178 178 vfy_tball_fname(bkpinfo, mountpoint, 179 set_number));179 set_number)); 180 180 } 181 181 g_last_afioball_number = set_number - 1; … … 253 253 iamhere("before vsbf"); 254 254 asprintf(&tmp, "Verifying %s#%d's big files", 255 media_descriptor_string(bkpinfo->backup_media_type),256 g_current_media_number);255 media_descriptor_string(bkpinfo->backup_media_type), 256 g_current_media_number); 257 257 open_evalcall_form(tmp); 258 258 paranoid_free(tmp); … … 293 293 } 294 294 asprintf(&tmp, "%s/%s", bkpinfo->restore_path, 295 biggiestruct.filename);295 biggiestruct.filename); 296 296 log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp); 297 297 if (!(forig = fopen(tmp, "r"))) { … … 314 314 if (bkpinfo->compression_level > 0) { 315 315 asprintf(&command, "cat %s | %s -dc 2>> %s", 316 slice_fname(bigfile_num, slice_num, mountpoint,317 bkpinfo->zip_suffix), sz_exe,318 MONDO_LOGFILE);316 slice_fname(bigfile_num, slice_num, mountpoint, 317 bkpinfo->zip_suffix), sz_exe, 318 MONDO_LOGFILE); 319 319 } else { 320 320 asprintf(&command, "cat %s", 321 slice_fname(bigfile_num, slice_num, mountpoint,322 bkpinfo->zip_suffix));321 slice_fname(bigfile_num, slice_num, mountpoint, 322 bkpinfo->zip_suffix)); 323 323 } 324 324 if ((pin = popen(command, "r"))) { … … 437 437 if (strstr(tarball_fname, ".bz2")) 438 438 asprintf(&command, 439 "star -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s",440 tarball_fname,441 (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog,442 outlog);439 "star -diff diffopts=mode,size,data file=%s %s >> %s 2>> %s", 440 tarball_fname, 441 (strstr(tarball_fname, ".bz2")) ? "-bz" : " ", outlog, 442 outlog); 443 443 } else { 444 444 bkpinfo->use_star = FALSE; 445 445 asprintf(&command, "afio -r -P %s -Z %s >> %s 2>> %s", 446 bkpinfo->zip_exe, tarball_fname, outlog, outlog);446 bkpinfo->zip_exe, tarball_fname, outlog, outlog); 447 447 } 448 448 log_msg(6, "command=%s", command); … … 454 454 } else { 455 455 asprintf(&command, "cat %s | cut -d':' -f%d | sort | uniq", outlog, 456 (bkpinfo->use_star) ? 1 : 2);456 (bkpinfo->use_star) ? 1 : 2); 457 457 pin = popen(command, "r"); 458 458 if (pin) { … … 569 569 asprintf(&tarball_fname, "%s/tmpfs/temporary-%s", bkpinfo->tmpdir, p); 570 570 /* BERLIOS : useless 571 asprintf(&tmp, "Temporarily copying file from tape to '%s'",572 573 log_it(tmp);574 paranoid_free(tmp);575 */571 asprintf(&tmp, "Temporarily copying file from tape to '%s'", 572 tarball_fname); 573 log_it(tmp); 574 paranoid_free(tmp); 575 */ 576 576 read_file_from_stream_to_file(bkpinfo, tarball_fname, size); 577 577 res = verify_a_tarball(bkpinfo, tarball_fname); 578 578 if (res) { 579 579 asprintf(&tmp, 580 "Afioball '%s' no longer matches your live filesystem", p); 580 "Afioball '%s' no longer matches your live filesystem", 581 p); 581 582 log_msg(0, tmp); 582 583 paranoid_free(tmp); … … 632 633 asprintf(&test_file, "%s/temporary-%s", bkpinfo->tmpdir, p); 633 634 /* BERLIOS: useless 634 asprintf(&tmp, 635 "Temporarily copying biggiefile %s's slices from tape to '%s'", 636 p, test_file); 637 log_it(tmp); 638 paranoid_free(tmp); 639 */ 640 for (res = read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr); 635 asprintf(&tmp, 636 "Temporarily copying biggiefile %s's slices from tape to '%s'", 637 p, test_file); 638 log_it(tmp); 639 paranoid_free(tmp); 640 */ 641 for (res = 642 read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr); 641 643 ctrl_chr != BLK_STOP_A_BIGGIE; 642 res = read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr)) { 644 res = 645 read_header_block_from_stream(&slice_siz, slice_fnam, 646 &ctrl_chr)) { 643 647 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 644 648 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); … … 646 650 res = read_file_from_stream_to_file(bkpinfo, test_file, slice_siz); 647 651 unlink(test_file); 648 res = read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr); 652 res = 653 read_header_block_from_stream(&slice_siz, slice_fnam, 654 &ctrl_chr); 649 655 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { 650 656 log_msg(2, "test_file = %s", test_file); … … 663 669 if (strcmp(biggie_cksum, orig_cksum)) { 664 670 asprintf(&tmp, "orig cksum=%s; curr cksum=%s", biggie_cksum, 665 orig_cksum);671 orig_cksum); 666 672 log_msg(2, tmp); 667 673 paranoid_free(tmp); 668 674 669 675 asprintf(&tmp, "%s has changed on live filesystem", 670 biggie_fname);676 biggie_fname); 671 677 log_to_screen(tmp); 672 678 paranoid_free(tmp); 673 679 674 680 asprintf(&tmp, "echo \"%s\" >> /tmp/biggies.changed", 675 biggie_fname);681 biggie_fname); 676 682 system(tmp); 677 683 paranoid_free(tmp); … … 715 721 716 722 asprintf(&curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ, 717 bkpinfo->tmpdir);723 bkpinfo->tmpdir); 718 724 asprintf(&curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ, 719 bkpinfo->tmpdir);725 bkpinfo->tmpdir); 720 726 log_to_screen("Verifying regular archives on tape"); 721 727 total_afioballs = get_last_filelist_number(bkpinfo) + 1; … … 745 751 res = read_header_block_from_stream(&size, fname, &ctrl_chr)) { 746 752 asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ, 747 bkpinfo->tmpdir, current_afioball_number);753 bkpinfo->tmpdir, current_afioball_number); 748 754 asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ, 749 bkpinfo->tmpdir, current_afioball_number);755 bkpinfo->tmpdir, current_afioball_number); 750 756 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 751 757 iamhere("Reading EXAT files from tape"); … … 769 775 if (res) { 770 776 asprintf(&tmp, "Afioball %ld differs from live filesystem", 771 current_afioball_number);777 current_afioball_number); 772 778 log_to_screen(tmp); 773 779 paranoid_free(tmp); … … 824 830 825 831 asprintf(&curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ, 826 bkpinfo->tmpdir);832 bkpinfo->tmpdir); 827 833 asprintf(&curr_acl_list_fname, ACL_BIGGLST_FNAME_RAW_SZ, 828 bkpinfo->tmpdir);834 bkpinfo->tmpdir); 829 835 asprintf(&comment, "Verifying all bigfiles."); 830 836 log_to_screen(comment); 831 837 /* 832 asprintf(&tmp, "%s/biggielist.txt", bkpinfo->tmpdir);833 noof_biggiefiles = count_lines_in_file (tmp); // pointless834 paranoid_free(tmp);835 */838 asprintf(&tmp, "%s/biggielist.txt", bkpinfo->tmpdir); 839 noof_biggiefiles = count_lines_in_file (tmp); // pointless 840 paranoid_free(tmp); 841 */ 836 842 res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr); 837 843 if (ctrl_chr != BLK_START_BIGGIEFILES) { … … 872 878 } 873 879 asprintf(&comment, "Verifying bigfile #%ld (%ld K)", 874 current_biggiefile_number, (long) size >> 10);880 current_biggiefile_number, (long) size >> 10); 875 881 update_progress_form(comment); 876 882 paranoid_free(comment); 877 883 878 asprintf(&logical_fname, "%s/%s", bkpinfo->restore_path, orig_fname); 879 res = verify_a_biggiefile_from_stream(bkpinfo, logical_fname, size); 884 asprintf(&logical_fname, "%s/%s", bkpinfo->restore_path, 885 orig_fname); 886 res = 887 verify_a_biggiefile_from_stream(bkpinfo, logical_fname, size); 880 888 paranoid_free(logical_fname); 881 889 retval += res; … … 929 937 asprintf(&mountpoint, "%s/cdrom", bkpinfo->tmpdir); 930 938 asprintf(&fname, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix, 931 bkpinfo->nfs_remote_dir, g_current_media_number);939 bkpinfo->nfs_remote_dir, g_current_media_number); 932 940 933 941 mkdir(mountpoint, 1777); … … 935 943 if (!does_file_exist(fname)) { 936 944 asprintf(&tmp, 937 "%s not found; assuming you backed up to CD; verifying CD...",938 fname);945 "%s not found; assuming you backed up to CD; verifying CD...", 946 fname); 939 947 log_msg(2, tmp); 940 948 paranoid_free(tmp); … … 957 965 if (ret) { 958 966 asprintf(&tmp, "make_vn of %s failed; unable to verify ISO\n", 959 fname);967 fname); 960 968 log_to_screen(tmp); 961 969 paranoid_free(tmp); … … 965 973 #else 966 974 asprintf(&command, "mount -o loop,ro -t iso9660 %s %s", fname, 967 mountpoint);975 mountpoint); 968 976 #endif 969 977 if (run_program_and_log_output(command, FALSE)) { 970 978 asprintf(&tmp, "%s failed; unable to mount ISO image\n", 971 command);979 command); 972 980 log_to_screen(tmp); 973 981 paranoid_free(tmp); … … 1008 1016 #endif 1009 1017 { 1010 asprintf(&tmp, "%s failed; unable to unmount ISO image\n", command); 1018 asprintf(&tmp, "%s failed; unable to unmount ISO image\n", 1019 command); 1011 1020 log_to_screen(tmp); 1012 1021 paranoid_free(tmp); … … 1073 1082 ("rm -f /tmp/biggies.changed /tmp/changed.files.[0-9]* 2> /dev/null"); 1074 1083 asprintf(&changed_files_fname, "/tmp/changed.files.%d", 1075 (int) (random() % 32767));1084 (int) (random() % 32767)); 1076 1085 asprintf(&tmp, 1077 "cat %s | grep -x \"%s:.*\" | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -v \"(total of\" | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"dev/.*\" > %s",1078 MONDO_LOGFILE, (bkpinfo->use_star) ? "star" : "afio",1079 changed_files_fname);1086 "cat %s | grep -x \"%s:.*\" | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -v \"(total of\" | grep -v \"incheckentry.*xwait\" | grep -vx \"/afio:.*\" | grep -vx \"dev/.*\" > %s", 1087 MONDO_LOGFILE, (bkpinfo->use_star) ? "star" : "afio", 1088 changed_files_fname); 1080 1089 log_msg(2, "Running command to derive list of changed files"); 1081 1090 log_msg(2, tmp); … … 1099 1108 if (diffs > 0) { 1100 1109 asprintf(&tmp, "cp -f %s %s", changed_files_fname, 1101 "/tmp/changed.files");1110 "/tmp/changed.files"); 1102 1111 run_program_and_log_output(tmp, FALSE); 1103 1112 paranoid_free(tmp); 1104 1113 1105 1114 asprintf(&tmp, 1106 "%ld files differed from live filesystem; type less %s or less %s to see",1107 diffs, changed_files_fname, "/tmp/changed.files");1115 "%ld files differed from live filesystem; type less %s or less %s to see", 1116 diffs, changed_files_fname, "/tmp/changed.files"); 1108 1117 log_msg(0, tmp); 1109 1118 paranoid_free(tmp); … … 1138 1147 assert_string_is_neither_NULL_nor_zerolength(mountpoint); 1139 1148 asprintf(&output, "%s/archives/%d.star.%s", mountpoint, setno, 1140 bkpinfo->zip_suffix);1149 bkpinfo->zip_suffix); 1141 1150 if (!does_file_exist(output)) { 1142 1151 paranoid_free(output); 1143 1152 asprintf(&output, "%s/archives/%d.afio.%s", mountpoint, setno, 1144 bkpinfo->zip_suffix);1153 bkpinfo->zip_suffix); 1145 1154 } 1146 1155 return (output); -
trunk/mondo/mondo/common/libmondo-verify.h
r30 r59 5 5 copyright : (C) 2002 by Stan Benoit 6 6 email : troff@nakedsoul.org 7 cvsid : $Id : libmondo-verify.h,v 1.4 2004/06/10 15:29:12 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 21 21 22 22 /** externals *************************************************************/ 23 int close_tape 24 extern void close_progress_form 25 extern long count_lines_in_file 26 extern bool does_file_exist 27 extern void exclude_nonexistent_files 28 extern void fatal_error 29 extern int find_and_mount_actual_cd 30 extern int find_cdrom_device 31 extern void finish 32 extern int get_last_filelist_number 33 extern long get_time 34 extern int grab_percentage_from_last_line_of_file 35 extern char *last_line_of_file 36 extern long long length_of_file 37 extern void log_file_end_to_screen 38 extern void log_tape_pos 39 extern char *marker_to_string 40 extern void open_evalcall_form 41 extern void open_progress_form 42 extern int openin_tape 43 extern void popup_and_OK 44 extern bool popup_and_get_string 45 extern int read_file_from_tape_to_file 46 long long);47 extern int read_header_block_from_tape 48 extern void setup_newt_stuff 49 extern char *slice_fname 50 extern long long space_occupied_by_cd 51 extern int strcmp_inc_numbers 52 extern char *strip_afio_output_line 53 extern char *trim_empty_quotes 54 extern void update_evalcall_form 55 extern void update_progress_form 56 extern int write_data_disks_to_tape 57 extern int write_header_block_to_tape 58 extern void wrong_marker 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); 59 59 60 60 … … 62 62 63 63 64 int verify_cd_image 65 int verify_a_tarball 66 int verify_an_afioball_from_CD 67 int verify_an_afioball_from_tape 68 int verify_a_biggiefile_from_tape 69 int verify_afioballs_from_CD 70 int verify_afioballs_from_tape 71 int verify_biggiefiles_from_tape 72 int verify_tape_backups 73 char *vfy_tball_fname 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); 74 74 75 75 … … 82 82 extern FILE *g_tape_stream; 83 83 extern long g_start_time, g_minimum_progress, g_maximum_progress, 84 84 g_current_progress, g_currentY; 85 85 extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN]; 86 86 extern int g_current_media_number; 87 87 88 extern void mvaddstr_and_log_it 88 extern void mvaddstr_and_log_it(int, int, char *); 89 89 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 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 *); -
trunk/mondo/mondo/common/libmondo.h
r30 r59 1 1 /* libmondo.h 2 * $Id : libmondo.h,v 1.2 2004/06/10 15:29:12 hugo Exp$2 * $Id$ 3 3 */ 4 4 … … 17 17 #include "libmondo-verify-EXT.h" 18 18 #include "libmondo-fifo-EXT.h" 19 -
trunk/mondo/mondo/common/mondostructures.h
r58 r59 35 35 * There is one mountlist_line for each device we're keeping track of in the mountlist. 36 36 */ 37 struct mountlist_line 38 { 37 struct mountlist_line { 39 38 /** 40 39 * The name of the device (/dev entry) for this mountlist line. Guaranteed to be unique. 41 40 */ 42 41 char device[64]; 43 42 44 43 /** … … 46 45 * This can be "raid", for a RAID subdisk, or "lvm", for an LVM PV. 47 46 */ 48 47 char mountpoint[256]; 49 48 50 49 /** … … 52 51 * Also, this can be "raid", for a RAID subdisk, or "lvm", for an LVM PV. 53 52 */ 54 53 char format[64]; 55 54 56 55 /** 57 56 * The size in kilobytes of this device. 0 or -1 indicates LVM. 58 57 */ 59 58 long long size; 60 59 61 60 /** 62 61 * For ext2 and ext3, this is the filesystem label (if there is one). If not, this should be "". 63 62 */ 64 63 char label[256]; 65 64 }; 66 65 … … 70 69 * system, so we can recreate them in a nuke restore. 71 70 */ 72 struct mountlist_itself 73 { 71 struct mountlist_itself { 74 72 /** 75 73 * Number of entries in the mountlist. 76 74 */ 77 75 int entries; 78 76 79 77 /** 80 78 * The list of entries, all @p entries of them. 81 79 */ 82 80 struct mountlist_line el[MAX_TAPECATALOG_ENTRIES]; 83 81 }; 84 82 … … 88 86 * ensure accurate resizing. 89 87 */ 90 struct mountlist_reference 91 { 88 struct mountlist_reference { 92 89 /** 93 90 * The number of entries in the list of mountlist references. 94 91 */ 95 92 int entries; 96 93 97 94 /** 98 95 * The array of mountlist_line, allocated on demand. 99 96 */ 100 97 struct mountlist_line **el; 101 98 }; 102 99 … … 104 101 * A line in @p additional_raid_variables. 105 102 */ 106 struct raid_var_line 107 { 103 struct raid_var_line { 108 104 /** 109 105 * The label for this RAID variable. 110 106 */ 111 107 char label[64]; 112 108 113 109 /** 114 110 * The value for this RAID variable. 115 111 */ 116 112 char value[64]; 117 113 }; 118 114 … … 123 119 * Each @p raid_device_record has one. 124 120 */ 125 struct additional_raid_variables 126 { 121 struct additional_raid_variables { 127 122 /** 128 123 * The number of entries in the list. 129 124 */ 130 125 int entries; 131 126 132 127 /** 133 128 * The list of entries, all @p entries of them. 134 129 */ 135 130 struct raid_var_line el[MAXIMUM_ADDITIONAL_RAID_VARS]; 136 131 }; 137 132 … … 139 134 * One disk in a @p list_of_disks. 140 135 */ 141 struct s_disk 142 { 136 struct s_disk { 143 137 #ifdef __FreeBSD__ 144 138 /** 145 139 * The name of this disk. If blank it will eventually get filled in automatically. 146 140 */ 147 141 char name[64]; 148 142 #endif 149 143 /** 150 144 * The device this entry describes. 151 145 */ 152 146 char device[64]; 153 147 154 148 /** 155 149 * Index number of this entry in the whole disklist. 156 150 */ 157 151 int index; 158 152 }; 159 153 … … 161 155 * A list of @p s_disk. Every @p raid_device_record has four. 162 156 */ 163 struct list_of_disks 164 { 157 struct list_of_disks { 165 158 /** 166 159 * The number of entries in the disklist. 167 160 */ 168 161 int entries; 169 162 170 163 /** 171 164 * The entries themselves, all @p entries of them. 172 165 */ 173 166 struct s_disk el[MAXIMUM_DISKS_PER_RAID_DEV]; 174 167 }; 175 168 … … 177 170 * A type of media we're backing up to. 178 171 */ 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 172 typedef 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; 189 182 190 183 /** 191 184 * A type of file in the catalog of recent archives. 192 185 */ 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 186 typedef 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; 197 190 198 191 199 192 #ifdef __FreeBSD__ 200 193 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 194 struct vinum_subdisk { 195 char which_device[64]; 196 }; 197 198 struct vinum_plex { 199 int raidlevel; 200 int stripesize; 201 int subdisks; 202 struct vinum_subdisk sd[MAXIMUM_RAID_DEVS]; 203 }; 204 205 struct vinum_volume { 206 char volname[64]; 207 int plexes; 208 struct vinum_plex plex[9]; 209 }; 210 211 struct 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 229 218 #else 230 219 231 220 /** 232 221 * A RAID device in the raidlist. 233 222 */ 234 struct raid_device_record 235 { 223 struct raid_device_record { 236 224 /** 237 225 * The name of the RAID device (e.g. /dev/md0). 238 226 */ 239 227 char raid_device[64]; 240 228 241 229 /** 242 230 * The RAID level (-1 to 5) we're using. 243 231 */ 244 232 int raid_level; 245 233 246 234 /** 247 235 * Whether the disk has a persistent superblock. 248 236 */ 249 237 int persistent_superblock; 250 238 251 239 /** 252 240 * The chunk size of this RAID device. 253 241 */ 254 242 int chunk_size; 255 243 256 244 /** 257 245 * A list of the disks to use for storing data. 258 246 */ 259 247 struct list_of_disks data_disks; 260 248 261 249 /** 262 250 * A list of the disks to use as "hot spares" in case one dies. 263 251 */ 264 252 struct list_of_disks spare_disks; 265 253 266 254 /** 267 255 * A list of the disks to use for storing parity information. 268 256 */ 269 257 struct list_of_disks parity_disks; 270 258 271 259 /** 272 260 * A list of the disks in this RAID device that have failed\. Rare. 273 261 */ 274 262 struct list_of_disks failed_disks; 275 263 276 264 /** 277 265 * The additional RAID variables for this device. 278 266 */ 279 280 281 282 267 struct additional_raid_variables additional_vars; 268 }; 269 270 /** 283 271 * The list of RAID devices. 284 272 * This is intended to be used along with the mountlist, and it can be 285 273 * directly loaded from/saved to raidtab format. 286 274 */ 287 struct raidlist_itself 288 { 275 struct raidlist_itself { 289 276 /** 290 277 * The number of entries in the list. 291 278 */ 292 279 int entries; 293 280 294 281 /** 295 282 * The RAID devices in the raidlist, all @p entries of them. 296 283 */ 297 298 284 struct raid_device_record el[MAXIMUM_RAID_DEVS]; 285 }; 299 286 300 287 #endif … … 316 303 * extremely strange and hard-to-track errors in chop_filelist(), since optimal_set_size is 0. 317 304 */ 318 struct s_bkpinfo 319 { 305 struct s_bkpinfo { 320 306 /** 321 307 * The device we're backing up to. … … 324 310 * If backup_media_type is anything else, this should be blank. 325 311 */ 326 char media_device[MAX_STR_LEN/4];312 char media_device[MAX_STR_LEN / 4]; 327 313 328 314 /** … … 333 319 * @bug This should probably be only one variable, not an array. 334 320 */ 335 long media_size[MAX_NOOF_MEDIA+1];321 long media_size[MAX_NOOF_MEDIA + 1]; 336 322 337 323 /** … … 347 333 * The function which_boot_loader() can help you set this. 348 334 */ 349 335 char boot_loader; 350 336 351 337 /** … … 354 340 * to take truncate_to_drive_name() of where_is_root_mounted(). 355 341 */ 356 char boot_device[MAX_STR_LEN/4];342 char boot_device[MAX_STR_LEN / 4]; 357 343 358 344 /** … … 361 347 * compression_level is 0. 362 348 */ 363 char zip_exe[MAX_STR_LEN/4];349 char zip_exe[MAX_STR_LEN / 4]; 364 350 365 351 /** … … 367 353 * bz2, gzip uses gz, etc. Do not include the dot. 368 354 */ 369 char zip_suffix[MAX_STR_LEN/4];355 char zip_suffix[MAX_STR_LEN / 4]; 370 356 371 357 /** … … 382 368 * This is a useful feature, but use at your own risk. 383 369 */ 384 char image_devs[MAX_STR_LEN/4];370 char image_devs[MAX_STR_LEN / 4]; 385 371 386 372 /** 387 373 * The compression level (1-9) to use. 0 disables compression. 388 374 */ 389 375 int compression_level; 390 376 391 377 /** … … 395 381 * and @p zip_suffix. 396 382 */ 397 383 bool use_lzo; 398 384 399 385 /** … … 403 389 * will be recompressed again. 404 390 */ 405 char do_not_compress_these[MAX_STR_LEN/2];391 char do_not_compress_these[MAX_STR_LEN / 2]; 406 392 407 393 /** 408 394 * If TRUE, then we should verify a backup. 409 395 */ 410 396 bool verify_data; 411 397 412 398 /** 413 399 * If TRUE, then we should back up some data. 414 400 */ 415 401 bool backup_data; 416 402 417 403 /** 418 404 * If TRUE, then we should restore some data. 419 405 */ 420 421 422 406 bool restore_data; 407 408 423 409 /** 424 410 * If TRUE, then we should backup/restore using star, not afio 425 411 */ 426 427 412 bool use_star; 413 428 414 429 415 /** 430 416 * Size of internal block reads/writes 431 417 */ 432 433 418 long internal_tape_block_size; 419 434 420 /** 435 421 * If TRUE, we're making a CD that will autonuke without confirmation when booted. 436 422 */ 437 423 bool disaster_recovery; 438 424 439 425 /** … … 442 428 * If backup_media_type is anything else, this is ignored. 443 429 */ 444 char isodir[MAX_STR_LEN/4];430 char isodir[MAX_STR_LEN / 4]; 445 431 446 432 /** … … 449 435 * If backup_media_type is anything else, this is ignored. 450 436 */ 451 char prefix[MAX_STR_LEN/4];437 char prefix[MAX_STR_LEN / 4]; 452 438 453 439 /** … … 456 442 * As such, it needs to be at least as large as the largest CD/DVD/ISO. 457 443 */ 458 char scratchdir[MAX_STR_LEN/4];444 char scratchdir[MAX_STR_LEN / 4]; 459 445 460 446 /** … … 464 450 * of space here. 465 451 */ 466 char tmpdir[MAX_STR_LEN/4];452 char tmpdir[MAX_STR_LEN / 4]; 467 453 468 454 /** … … 471 457 * needn't set it yourself. 472 458 */ 473 459 long optimal_set_size; 474 460 475 461 /** 476 462 * The type of media we're backing up to. 477 463 */ 478 464 t_bkptype backup_media_type; 479 465 // bool blank_dvd_first; 480 466 … … 484 470 * If FALSE, then we use the filelist whose name is specified in @p include_paths. 485 471 */ 486 472 bool make_filelist; 487 473 488 474 /** … … 491 477 * If you do nothing, "/" will be used. 492 478 */ 493 479 char include_paths[MAX_STR_LEN]; 494 480 495 481 /** … … 498 484 * the scratchdir, and the tempdir are automatically excluded. 499 485 */ 500 486 char exclude_paths[MAX_STR_LEN]; 501 487 502 488 /** … … 505 491 * without overwriting the old ones. Ignored during a backup. 506 492 */ 507 493 char restore_path[MAX_STR_LEN]; 508 494 509 495 /** 510 496 * A command to call BEFORE making an ISO image. 511 497 */ 512 498 char call_before_iso[MAX_STR_LEN]; 513 499 514 500 /** 515 501 * A command to call to make an ISO image. 516 502 */ 517 503 char call_make_iso[MAX_STR_LEN]; 518 504 519 505 /** 520 506 * A command to call to burn the ISO image. 521 507 */ 522 508 char call_burn_iso[MAX_STR_LEN]; 523 509 524 510 /** 525 511 * A command to call AFTER making an ISO image. 526 512 */ 527 513 char call_after_iso[MAX_STR_LEN]; 528 514 529 515 /** … … 531 517 * included with Mindi. 532 518 */ 533 519 char kernel_path[MAX_STR_LEN]; 534 520 535 521 /** … … 539 525 * address form. (Domain names will be resolved in post_param_configuration().) 540 526 */ 541 527 char nfs_mount[MAX_STR_LEN]; 542 528 543 529 /** … … 545 531 * the backups in. 546 532 */ 547 533 char nfs_remote_dir[MAX_STR_LEN]; 548 534 549 535 /** … … 551 537 * after nuking the system. If "", do not use a post-nuke tarball. 552 538 */ 553 539 char postnuke_tarball[MAX_STR_LEN]; 554 540 555 541 /** … … 557 543 * writing to them. This has no effect for DVDs. 558 544 */ 559 545 bool wipe_media_first; 560 546 561 547 // patch by Herman Kuster … … 564 550 * (files changed since last full backup) are supported. 565 551 */ 566 552 int differential; 567 553 // end patch 568 554 … … 570 556 * If TRUE, then don't eject media when backing up or restoring. 571 557 */ 572 558 bool please_dont_eject; 573 559 574 560 /** 575 561 * The speed of the CD-R[W] drive. 576 562 */ 577 563 int cdrw_speed; 578 564 579 565 /** … … 582 568 * it probably falls into this category. 583 569 */ 584 570 bool manual_cd_tray; 585 571 586 572 /** … … 588 574 * or so. It is useful in testing. Use with care. 589 575 */ 590 576 bool nonbootable_backup; 591 577 592 578 /** 593 579 * If TRUE, make the bootable CD use LILO/ELILO. If FALSE, use isolinux (the default). 594 580 */ 595 581 bool make_cd_use_lilo; 596 582 }; 597 583 … … 603 589 * @bug My understanding of this structure is horrendously incomplete. Could you please fill in the details? 604 590 */ 605 struct s_node 606 { 591 struct s_node { 607 592 /** 608 593 * The character this node contains. 609 594 */ 610 595 char ch; 611 596 612 597 /** 613 598 * The node to the right of this one. 614 599 */ 615 600 struct s_node *right; 616 601 617 602 /** 618 603 * The node below this one. 619 604 */ 620 605 struct s_node *down; 621 606 622 607 /** 623 608 * If TRUE, then this node is selected (for restore, for example). 624 609 */ 625 610 bool selected; 626 611 627 612 /** 628 613 * If TRUE, then we want to see the directories below this one. 629 614 */ 630 615 bool expanded; 631 616 }; 632 617 … … 638 623 */ 639 624 struct s_wrapfifo { 640 625 /** 641 626 * The device we write to or read from (a FIFO). 642 627 */ 643 char public_device[MAX_STR_LEN /4];644 645 628 char public_device[MAX_STR_LEN / 4]; 629 630 /** 646 631 * The actual device that data from the FIFO should be buffered and written to. 647 632 */ 648 char private_device[MAX_STR_LEN /4];649 650 633 char private_device[MAX_STR_LEN / 4]; 634 635 /** 651 636 * A buffer for holding data read from the FIFO. 652 637 */ 653 char internal_buffer_IN_fifo[MAX_STR_LEN /4];654 655 638 char internal_buffer_IN_fifo[MAX_STR_LEN / 4]; 639 640 /** 656 641 * A buffer for holding data to be written to the FIFO. 657 642 */ 658 char internal_buffer_OUT_fifo[MAX_STR_LEN /4];659 660 643 char internal_buffer_OUT_fifo[MAX_STR_LEN / 4]; 644 645 /** 661 646 * If TRUE, then we're writing directly to the tape streamer; if FALSE, we're writing to the FIFO. 662 647 */ … … 672 657 */ 673 658 struct s_filename_and_lstat_info { 674 659 /** 675 660 * The filename of the file this structure is describing. 676 661 */ 677 662 char filename[MAX_STR_LEN]; 678 663 679 664 /** 680 665 * The MD5 checksum (32 hex digits) of this file. 681 666 */ 682 667 char checksum[64]; 683 668 684 669 /** 685 670 * Unused; kept for backwards compatibility. 686 671 */ 687 672 char for_backward_compatibility; 688 673 689 674 /** 690 675 * The stat buffer for this file. 691 676 * Generated with a call to <tt>lstat(&(struc->properties))</tt> where @p struc … … 701 686 */ 702 687 struct s_filelist_entry { 703 688 /** 704 689 * The name of the file. 705 690 */ 706 691 char filename[MAX_STR_LEN]; 707 692 /** 708 693 * The severity if the file has changed between the backup and live filesystem. 709 694 * This is on a scale from 1 to 3, 3 being the most important. File patterns which cause … … 737 722 * @see severity_of_difference 738 723 */ 739 724 int severity; 740 725 }; 741 726 … … 745 730 */ 746 731 struct s_filelist { 747 732 /** 748 733 * The number of entries in the list. 749 734 */ 750 751 752 735 int entries; 736 737 /** 753 738 * The entries themselves, all @p entries of them. 754 739 */ … … 761 746 */ 762 747 struct s_tapecat_entry { 763 748 /** 764 749 * The type of archive it is (afioball, slice, or something else). 765 750 */ 766 751 t_archtype type; 767 752 768 753 /** 769 754 * The filelist number or biggiefile (not slice!) number. 770 755 */ 771 756 int number; 772 757 773 758 /** 774 759 * The slice number if it's a biggiefile. 775 760 */ 776 761 long aux; 777 762 778 763 /** 779 764 * The tape position at the point this entry was added. 780 765 */ 781 766 long long tape_posK; 782 767 783 768 /** 784 769 * The filename of the file cataloged here. 785 770 */ 786 char fname[MAX_TAPECAT_FNAME_LEN +1];771 char fname[MAX_TAPECAT_FNAME_LEN + 1]; 787 772 }; 788 773 … … 792 777 */ 793 778 struct s_tapecatalog { 794 779 /** 795 780 * The number of entries in the tape catalog. 796 781 */ 797 782 int entries; 798 783 799 784 /** 800 785 * The entries themselves, all @p entries of them. 801 786 */ … … 806 791 807 792 struct s_mdrec { 808 int md; 809 int raidlevel; // 0, 1, 5793 int md; // /dev/mdN 794 int raidlevel; // 0, 1, 5 810 795 struct list_of_disks disks; 811 796 int progress; … … 816 801 struct s_mdrec el[MAXIMUM_RAID_DEVS]; 817 802 }; 818 -
trunk/mondo/mondo/common/my-stuff.h
r41 r59 207 207 #if defined(DEBUG) && !__cplusplus 208 208 int count; 209 char trace_log[255]; /*buffer for logging */209 char trace_log[255]; /*buffer for logging */ 210 210 char *trace_log_ptr; 211 #endif 211 #endif /* DEBUG */ 212 212 213 213 #define IA64_BOOT_SIZE "8192" /* Should be coherent with mindi */ … … 240 240 #undef assert 241 241 242 extern void _mondo_assert_fail (const char *file, const char *function, int line, const char *exp); 242 extern void _mondo_assert_fail(const char *file, const char *function, 243 int line, const char *exp); 243 244 244 245 /** … … 251 252 #endif 252 253 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 260 #define NOOF_ERR_LINES 6 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. 261 262 #define ARBITRARY_MAXIMUM 500 ///< The maximum number of items showing at once in the mountlist or filelist editor. 262 #define MAX_TAPECATALOG_ENTRIES 4096 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. 264 265 #define MAXIMUM_RAID_DEVS 32 ///< The maximum number of RAID devices in the raidlist. 265 #define MAXIMUM_ADDITIONAL_RAID_VARS 32 266 #define MAXIMUM_DISKS_PER_RAID_DEV 32 267 268 #define RAIDTAB_FNAME "/etc/raidtab" 269 270 #define BLK_START_OF_BACKUP 1 271 #define BLK_START_OF_TAPE 2 272 #define BLK_START_AFIOBALLS 10 273 #define BLK_STOP_AFIOBALLS 19 274 #define BLK_START_AN_AFIO_OR_SLICE 20 275 #define BLK_STOP_AN_AFIO_OR_SLICE 29 276 #define BLK_START_BIGGIEFILES 30 277 #define BLK_STOP_BIGGIEFILES 39 278 #define BLK_START_A_NORMBIGGIE 40 279 #define BLK_START_A_PIHBIGGIE 41 280 #define BLK_START_EXTENDED_ATTRIBUTES 45 281 #define BLK_STOP_EXTENDED_ATTRIBUTES 46 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 282 283 #define BLK_START_EXAT_FILE 47 283 284 #define BLK_STOP_EXAT_FILE 48 284 #define BLK_STOP_A_BIGGIE 59 285 #define BLK_START_FILE 80 286 #define BLK_STOP_FILE 89 287 #define BLK_END_OF_TAPE 100 288 #define BLK_END_OF_BACKUP 101 289 #define BLK_ABORTED_BACKUP 102 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. 290 291 291 292 /// The external tape blocksize. 292 293 #ifdef EXTTAPE 293 294 #define TAPE_BLOCK_SIZE (long)EXTTAPE 294 295 #else 295 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. 304 305 305 306 … … 349 350 /** 350 351 * @c growisofs command to generate a bootable DVD using LILO, except for the directory to image. 351 */// -b images/mindi-boot.2880.img352 */// -b images/mindi-boot.2880.img 352 353 #define MONDO_GROWISOFS_REGULAR_ELILO "growisofs -use-the-force-luke -no-emul-boot -b images/mindi-boot.2880.img -c boot.cat -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ -v" 353 354 354 355 /** 355 356 * @c growisofs command to generate a bootable DVD using LILO, except for the directory to image. 356 */// -b images/mindi-boot.2880.img357 */// -b images/mindi-boot.2880.img 357 358 #define MONDO_GROWISOFS_REGULAR_LILO "growisofs -no-emul-boot -b isolinux.bin -c boot.cat -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ -v" 358 359 … … 460 461 /** @def CP_BIN The GNU @c cp binary to use. */ 461 462 #ifdef __FreeBSD__ 462 463 464 465 466 467 468 469 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" 470 471 #else 471 472 473 474 475 476 477 478 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" 479 480 #endif 480 481 … … 496 497 */ 497 498 #define AFIOBALL_FNAME_RAW_SZ (bkpinfo->use_star)?"%s/tmpfs/%ld.star.%s":"%s/tmpfs/%ld.afio.%s" 498 #define ARCH_THREADS 2 499 #define ARCH_BUFFER_NUM (ARCH_THREADS*4) 500 #define FORTY_SPACES " " 501 #define PPCFG_RAMDISK_SIZE 250 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). 502 503 503 504 #define DO_MBR_PLEASE "/tmp/DO-MBR-PLEASE" … … 514 515 #define log_msg(level, format, args...) log_debug_msg(level, __FILE__, __FUNCTION__, __LINE__, format, ## args) 515 516 516 #define DEFAULT_DVD_DISK_SIZE 4380 517 518 #define DEFAULT_DEBUG_LEVEL 4 519 520 #define SZ_PARTIMAGE_VOLSIZE "1048576" 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 521 522 #define PARTIMAGE_PARAMS "-z0 -V" SZ_PARTIMAGE_VOLSIZE " -o -b -d -g1" 522 523 … … 524 525 #define MNT_FLOPPY "/mnt/floppy" 525 526 526 #define FREELOADER 527 #define FREELOADER // You're not a paying customer 527 528 #define DEFAULT_MR_LOGLEVEL 4 528 529 … … 530 531 #define _GNU_SOURCE 531 532 532 #endif 533 #endif /* _MY_STUFF_H_ */ -
trunk/mondo/mondo/common/newt-specific-EXT.h
r30 r59 2 2 3 3 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); 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, 13 long max_val); 14 extern void log_file_end_to_screen(char *filename, char *grep_for_me); 15 extern void log_to_screen(const char *fmt, ...); 16 extern void popup_and_OK(char *prompt); 17 extern bool popup_and_get_string(char *title, char *b, char *output, 18 int maxsize); 19 extern bool popup_with_buttons(char *p, char *button1, char *button2); 20 extern void refresh_log_screen(); 21 extern void setup_newt_stuff(); 22 extern void update_evalcall_form_ratio(int num, int denom); 23 extern void update_evalcall_form(int curr); 24 extern void update_progress_form(char *blurb3); 25 extern void update_progress_form_full(char *blurb1, char *blurb2, 26 char *blurb3); 24 27 25 28 … … 27 30 28 31 29 extern t_bkptype which_backup_media_type 30 extern int which_compression_level 32 extern t_bkptype which_backup_media_type(bool); 33 extern int which_compression_level(); 31 34 32 35 33 extern void popup_changelist_from_file(char *source_file);36 extern void popup_changelist_from_file(char *source_file); 34 37 35 38 extern pid_t g_main_pid; -
trunk/mondo/mondo/common/newt-specific.c
r58 r59 112 112 * @return TRUE for yes; FALSE for no. 113 113 */ 114 114 bool ask_me_yes_or_no(char *prompt) { 115 115 116 116 /*@ buffers ********************************************************** */ … … 119 119 size_t n = 0; 120 120 121 assert_string_is_neither_NULL_nor_zerolength(prompt);121 assert_string_is_neither_NULL_nor_zerolength(prompt); 122 122 123 123 if (g_text_mode) { … … 221 221 * Close the currently opened progress form. 222 222 */ 223 void224 close_progress_form() {225 if (g_text_mode) {226 return;227 }228 if (g_current_progress == -999) {229 log_msg(2,230 "Trying to close the progress form when it ain't open!");231 return;232 }233 g_current_progress = g_maximum_progress;234 update_progress_form("Complete");235 sleep(1);236 if (g_text_mode) {237 log_msg(2, "Closing progress form");238 return;239 }240 newtPopHelpLine();241 newtFormDestroy(g_progressForm);242 newtPopWindow();243 g_progressForm = NULL;244 g_current_progress = -999;245 }223 void 224 close_progress_form() { 225 if (g_text_mode) { 226 return; 227 } 228 if (g_current_progress == -999) { 229 log_msg(2, 230 "Trying to close the progress form when it ain't open!"); 231 return; 232 } 233 g_current_progress = g_maximum_progress; 234 update_progress_form("Complete"); 235 sleep(1); 236 if (g_text_mode) { 237 log_msg(2, "Closing progress form"); 238 return; 239 } 240 newtPopHelpLine(); 241 newtFormDestroy(g_progressForm); 242 newtPopWindow(); 243 g_progressForm = NULL; 244 g_current_progress = -999; 245 } 246 246 247 247 … … 422 422 } 423 423 if (grep_for_me[0] != '\0') { 424 asprintf(&command, "cat %s | grep \"%s\" | tail -n%d", filename,425 grep_for_me, g_noof_log_lines);424 asprintf(&command, "cat %s | grep \"%s\" | tail -n%d", 425 filename, grep_for_me, g_noof_log_lines); 426 426 } else { 427 427 asprintf(&command, "cat %s | tail -n%d", filename, 428 g_noof_log_lines);428 g_noof_log_lines); 429 429 } 430 430 fin = popen(command, "r"); … … 1202 1202 static char *possible_responses[] = 1203 1203 { "none", "cdr", "cdrw", "dvd", "tape", "cdstream", "udev", 1204 "nfs", "iso", NULL }; 1204 "nfs", "iso", NULL 1205 }; 1205 1206 char *outstr; 1206 1207 t_bkptype backup_type; -
trunk/mondo/mondo/common/newt-specific.h
r30 r59 1 1 /* newt-specific.h 2 * $Id : newt-specific.h,v 1.3 2004/06/10 15:29:12 hugo Exp$2 * $Id$ 3 3 */ 4 4 … … 8 8 #endif 9 9 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); 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, 21 long max_val); 22 void popup_and_OK(char *prompt); 23 bool popup_and_get_string(char *title, char *b, char *output, int maxsize); 24 bool popup_with_buttons(char *p, char *button1, char *button2); 25 void refresh_log_screen(); 26 void setup_newt_stuff(); 27 void update_evalcall_form_ratio(int num, int denom); 28 void update_evalcall_form(int curr); 29 void update_progress_form(char *blurb3); 30 void update_progress_form_full(char *blurb1, char *blurb2, char *blurb3); 30 31 31 32 … … 34 35 35 36 36 t_bkptype which_backup_media_type 37 int which_compression_level 37 t_bkptype which_backup_media_type(bool); 38 int which_compression_level(); 38 39 39 40 40 void popup_changelist_from_file(char *source_file);41 void popup_changelist_from_file(char *source_file); -
trunk/mondo/mondo/mondoarchive/main.c
r30 r59 5 5 copyright : (C) 2002 by Stan Benoit 6 6 email : troff@nakedsoul.org 7 cvsid : $Id : main.c,v 1.14 2004/06/21 20:20:36 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 127 127 128 128 // for CVS 129 //static char cvsid[] = "$Id : main.c,v 1.14 2004/06/21 20:20:36 hugo Exp$";129 //static char cvsid[] = "$Id$"; 130 130 131 131 /************************* external variables *************************/ 132 132 extern void set_signals(int); 133 133 extern int g_current_media_number; 134 extern void register_pid(pid_t, char *);134 extern void register_pid(pid_t, char *); 135 135 extern int g_currentY; 136 136 extern bool g_text_mode; … … 141 141 extern char *g_erase_tmpdir_and_scratchdir; 142 142 extern char *g_cdrw_drive_is_here; 143 static char *g_cdrom_drive_is_here =NULL;144 static char *g_dvd_drive_is_here =NULL;143 static char *g_cdrom_drive_is_here = NULL; 144 static char *g_dvd_drive_is_here = NULL; 145 145 extern double g_kernel_version; 146 146 … … 160 160 void welcome_to_mondoarchive() 161 161 { 162 log_msg (0, "Mondo Archive v%s --- http://www.mondorescue.org", VERSION); 163 log_msg (0, "running on %s architecture",get_architecture()); 164 log_msg (0,"-----------------------------------------------------------"); 165 log_msg (0, "NB: Mondo logs almost everything, so don't panic if you see"); 166 log_msg (0, "some error messages. Please read them carefully before you"); 167 log_msg (0, "decide to break out in a cold sweat. Despite (or perhaps"); 168 log_msg (0, "because of) the wealth of messages. some users are inclined"); 169 log_msg (0, "to stop reading this log. If Mondo stopped for some reason,"); 170 log_msg (0, "chances are it's detailed here. More than likely there's a"); 171 log_msg (0, "message at the very end of this log that will tell you what"); 172 log_msg (0, "is wrong. Please read it! -Devteam"); 173 log_msg (0,"-----------------------------------------------------------"); 174 175 log_msg (0, "Zero..."); 176 log_msg (1, "One..."); 177 log_msg (2, "Two..."); 178 log_msg (3, "Three..."); 179 log_msg (4, "Four..."); 180 log_msg (5, "Five..."); 181 log_msg (6, "Six..."); 182 log_msg (7, "Seven..."); 183 log_msg (8, "Eight..."); 184 printf ("See %s for details of backup run.\n", MONDO_LOGFILE); 162 log_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org", 163 VERSION); 164 log_msg(0, "running on %s architecture", get_architecture()); 165 log_msg(0, 166 "-----------------------------------------------------------"); 167 log_msg(0, 168 "NB: Mondo logs almost everything, so don't panic if you see"); 169 log_msg(0, 170 "some error messages. Please read them carefully before you"); 171 log_msg(0, 172 "decide to break out in a cold sweat. Despite (or perhaps"); 173 log_msg(0, 174 "because of) the wealth of messages. some users are inclined"); 175 log_msg(0, 176 "to stop reading this log. If Mondo stopped for some reason,"); 177 log_msg(0, 178 "chances are it's detailed here. More than likely there's a"); 179 log_msg(0, 180 "message at the very end of this log that will tell you what"); 181 log_msg(0, 182 "is wrong. Please read it! -Devteam"); 183 log_msg(0, 184 "-----------------------------------------------------------"); 185 186 log_msg(0, "Zero..."); 187 log_msg(1, "One..."); 188 log_msg(2, "Two..."); 189 log_msg(3, "Three..."); 190 log_msg(4, "Four..."); 191 log_msg(5, "Five..."); 192 log_msg(6, "Six..."); 193 log_msg(7, "Seven..."); 194 log_msg(8, "Eight..."); 195 printf("See %s for details of backup run.\n", MONDO_LOGFILE); 185 196 } 186 197 … … 194 205 void distro_specific_kludges_at_start_of_mondoarchive() 195 206 { 196 log_msg (2, "Unmounting old ramdisks if necessary"); 197 stop_magicdev_if_necessary(); // for RH+Gnome users 198 run_program_and_log_output("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2); 199 unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted 200 // stop_autofs_if_necessary(); // for Xandros users 201 mount_boot_if_necessary(); // for Gentoo users with non-mounted /boot partitions 202 clean_up_KDE_desktop_if_necessary(); // delete various misc ~/.* files that get in the way 207 log_msg(2, "Unmounting old ramdisks if necessary"); 208 stop_magicdev_if_necessary(); // for RH+Gnome users 209 run_program_and_log_output 210 ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2); 211 unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted 212 // stop_autofs_if_necessary(); // for Xandros users 213 mount_boot_if_necessary(); // for Gentoo users with non-mounted /boot partitions 214 clean_up_KDE_desktop_if_necessary(); // delete various misc ~/.* files that get in the way 203 215 } 204 216 … … 211 223 { 212 224 // char tmp[500]; 213 log_msg(2, "Restarting magicdev if necessary");214 215 restart_magicdev_if_necessary();// for RH+Gnome users216 217 log_msg(2, "Restarting autofs if necessary");218 219 220 221 log_msg(2, "Restarting supermounts if necessary");222 223 remount_supermounts_if_necessary();// for Mandrake users224 225 log_msg(2, "Unmounting /boot if necessary");226 227 unmount_boot_if_necessary();// for Gentoo users225 log_msg(2, "Restarting magicdev if necessary"); 226 sync(); 227 restart_magicdev_if_necessary(); // for RH+Gnome users 228 229 log_msg(2, "Restarting autofs if necessary"); 230 sync(); 231 // restart_autofs_if_necessary(); // for Xandros users 232 233 log_msg(2, "Restarting supermounts if necessary"); 234 sync(); 235 remount_supermounts_if_necessary(); // for Mandrake users 236 237 log_msg(2, "Unmounting /boot if necessary"); 238 sync(); 239 unmount_boot_if_necessary(); // for Gentoo users 228 240 229 241 // log_msg( 2, "Cleaning up KDE desktop"); … … 240 252 * What did you think it did, anyway? :-) 241 253 */ 242 int 243 main (int argc, char *argv[]) 254 int main(int argc, char *argv[]) 244 255 { 245 246 247 248 256 struct s_bkpinfo *bkpinfo; 257 char *tmp; 258 int res, retval; 259 char *say_at_end; 249 260 250 261 /* Make sure I'm root; abort if not */ 251 if (getuid () != 0) 252 { 253 fprintf (stderr, "Please run as root.\r\n"); 254 exit (127); 255 } 262 if (getuid() != 0) { 263 fprintf(stderr, "Please run as root.\r\n"); 264 exit(127); 265 } 256 266 257 267 /* If -V, -v or --version then echo version no. and quit */ 258 if (argc==2 && (!strcmp(argv[argc-1], "-v") || !strcmp(argv[argc-1], "-V") || !strcmp(argv[argc-1], "--version"))) 259 { printf("mondoarchive v%s\nSee man page for help\n", VERSION); exit(0); } 268 if (argc == 2 269 && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V") 270 || !strcmp(argv[argc - 1], "--version"))) { 271 printf("mondoarchive v%s\nSee man page for help\n", VERSION); 272 exit(0); 273 } 260 274 261 275 /* Initialize variables */ 262 276 263 malloc_libmondo_global_strings(); 264 malloc_string(tmp); 265 malloc_string(say_at_end); 266 267 res = 0; 268 retval = 0; 269 diffs = 0; 270 say_at_end[0] = '\0'; 271 unlink("/var/log/partimagehack-debug.log"); 272 printf ("Initializing...\n"); 273 if (!(bkpinfo = malloc(sizeof(struct s_bkpinfo)))) { fatal_error("Cannot malloc bkpinfo"); } 277 malloc_libmondo_global_strings(); 278 malloc_string(tmp); 279 malloc_string(say_at_end); 280 281 res = 0; 282 retval = 0; 283 diffs = 0; 284 say_at_end[0] = '\0'; 285 unlink("/var/log/partimagehack-debug.log"); 286 printf("Initializing...\n"); 287 if (!(bkpinfo = malloc(sizeof(struct s_bkpinfo)))) { 288 fatal_error("Cannot malloc bkpinfo"); 289 } 274 290 275 291 276 292 /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */ 277 strncpy(tmp, getenv("PATH"), MAX_STR_LEN-1); 278 tmp[MAX_STR_LEN-1] = '\0'; 279 if (strlen(tmp)>=MAX_STR_LEN-33) 280 { fatal_error("Your PATH environmental variable is too long. Please shorten it."); } 281 strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin"); 282 setenv("PATH", tmp, 1); 293 strncpy(tmp, getenv("PATH"), MAX_STR_LEN - 1); 294 tmp[MAX_STR_LEN - 1] = '\0'; 295 if (strlen(tmp) >= MAX_STR_LEN - 33) { 296 fatal_error 297 ("Your PATH environmental variable is too long. Please shorten it."); 298 } 299 strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin"); 300 setenv("PATH", tmp, 1); 283 301 284 302 /* Add the ARCH environment variable for ia64 purposes */ 285 strncpy(tmp, get_architecture(), MAX_STR_LEN-1);286 tmp[MAX_STR_LEN-1] = '\0';287 288 289 303 strncpy(tmp, get_architecture(), MAX_STR_LEN - 1); 304 tmp[MAX_STR_LEN - 1] = '\0'; 305 setenv("ARCH", tmp, 1); 306 307 unlink(MONDO_LOGFILE); 290 308 291 309 /* Configure the bkpinfo structure, global file paths, etc. */ 292 g_main_pid = getpid(); 293 log_msg(9, "This"); 294 295 register_pid(g_main_pid, "mondo"); 296 set_signals(TRUE); // catch SIGTERM, etc. 297 nice(10); 298 run_program_and_log_output("dmesg -n1", TRUE); 299 300 log_msg(9, "Next"); 301 welcome_to_mondoarchive(); 302 distro_specific_kludges_at_start_of_mondoarchive(); 303 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir); 304 g_kernel_version = get_kernel_version(); 305 306 if (argc==4 && !strcmp(argv[1], "getfattr")) 307 { 308 g_loglevel = 10; 309 g_text_mode = TRUE; 310 setup_newt_stuff(); 311 if (!strstr(argv[2], "filelist")) 312 { 313 printf("Sorry - filelist goes first\n"); 314 finish(1); 315 } 316 else 317 { 318 finish(get_fattr_list(argv[2], argv[3])); 319 } 320 finish(0); 321 } 322 if (argc==4 && !strcmp(argv[1], "setfattr")) 323 { 324 g_loglevel = 10; 310 g_main_pid = getpid(); 311 log_msg(9, "This"); 312 313 register_pid(g_main_pid, "mondo"); 314 set_signals(TRUE); // catch SIGTERM, etc. 315 nice(10); 316 run_program_and_log_output("dmesg -n1", TRUE); 317 318 log_msg(9, "Next"); 319 welcome_to_mondoarchive(); 320 distro_specific_kludges_at_start_of_mondoarchive(); 321 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, 322 bkpinfo->scratchdir); 323 g_kernel_version = get_kernel_version(); 324 325 if (argc == 4 && !strcmp(argv[1], "getfattr")) { 326 g_loglevel = 10; 327 g_text_mode = TRUE; 328 setup_newt_stuff(); 329 if (!strstr(argv[2], "filelist")) { 330 printf("Sorry - filelist goes first\n"); 331 finish(1); 332 } else { 333 finish(get_fattr_list(argv[2], argv[3])); 334 } 335 finish(0); 336 } 337 if (argc == 4 && !strcmp(argv[1], "setfattr")) { 338 g_loglevel = 10; 325 339 // chdir("/tmp"); 326 g_text_mode = TRUE; 327 setup_newt_stuff(); 328 finish(set_fattr_list(argv[2], argv[3])); 329 } 330 331 if (argc==3 && !strcmp(argv[1], "wildcards")) 332 { 333 g_loglevel = 10; 334 g_text_mode = TRUE; 335 setup_newt_stuff(); 336 turn_wildcard_chars_into_literal_chars(tmp, argv[2]); 337 printf("in=%s; out=%s\n", argv[2], tmp); 338 finish(1); 339 } 340 341 if (argc==4 && !strcmp(argv[1], "getfacl")) 342 { 343 g_loglevel = 10; 344 g_text_mode = TRUE; 345 setup_newt_stuff(); 346 if (!strstr(argv[2], "filelist")) 347 { 348 printf("Sorry - filelist goes first\n"); 349 finish(1); 350 } 351 else 352 { 353 finish(get_acl_list(argv[2], argv[3])); 354 } 355 finish(0); 356 } 357 if (argc==4 && !strcmp(argv[1], "setfacl")) 358 { 359 g_loglevel = 10; 340 g_text_mode = TRUE; 341 setup_newt_stuff(); 342 finish(set_fattr_list(argv[2], argv[3])); 343 } 344 345 if (argc == 3 && !strcmp(argv[1], "wildcards")) { 346 g_loglevel = 10; 347 g_text_mode = TRUE; 348 setup_newt_stuff(); 349 turn_wildcard_chars_into_literal_chars(tmp, argv[2]); 350 printf("in=%s; out=%s\n", argv[2], tmp); 351 finish(1); 352 } 353 354 if (argc == 4 && !strcmp(argv[1], "getfacl")) { 355 g_loglevel = 10; 356 g_text_mode = TRUE; 357 setup_newt_stuff(); 358 if (!strstr(argv[2], "filelist")) { 359 printf("Sorry - filelist goes first\n"); 360 finish(1); 361 } else { 362 finish(get_acl_list(argv[2], argv[3])); 363 } 364 finish(0); 365 } 366 if (argc == 4 && !strcmp(argv[1], "setfacl")) { 367 g_loglevel = 10; 360 368 // chdir("/tmp"); 361 g_text_mode = TRUE; 362 setup_newt_stuff(); 363 finish(set_acl_list(argv[2], argv[3])); 364 } 365 366 if (argc>2 && !strcmp(argv[1], "find-cd")) 367 { 368 g_loglevel = 10; 369 g_text_mode = TRUE; 370 setup_newt_stuff(); 371 if (find_cdrw_device(tmp)) 372 { printf("Failed to find CDR-RW drive\n"); } 373 else 374 { printf("CD-RW is at %s\n", tmp); } 375 tmp[0] = '\0'; 376 if (find_cdrom_device(tmp, atoi(argv[2]))) 377 { printf("Failed to find CD-ROM drive\n"); } 378 else 379 { printf("CD-ROM is at %s\n", tmp); } 380 finish(0); 381 } 382 383 if (argc>2 && !strcmp(argv[1], "find-dvd")) 384 { 385 g_loglevel = 10; 386 g_text_mode = TRUE; 387 setup_newt_stuff(); 388 if (find_dvd_device(tmp, atoi(argv[2]))) 389 { printf("Failed to find DVD drive\n"); } 390 else 391 { printf("DVD is at %s\n", tmp); } 392 finish(0); 393 } 394 395 if (argc>2 && !strcmp(argv[1], "disksize")) 396 { 397 printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2])); 398 finish(0); 399 } 400 if (argc>2 && !strcmp(argv[1], "test-dev")) 401 { 402 if (is_dev_an_NTFS_dev(argv[2])) 403 { printf("%s is indeed an NTFS dev\n", argv[2]); } 404 else 405 { printf("%s is _not_ an NTFS dev\n", argv[2]); } 406 finish(0); 407 } 408 409 if (pre_param_configuration(bkpinfo)) { fatal_error("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting..."); } 410 369 g_text_mode = TRUE; 370 setup_newt_stuff(); 371 finish(set_acl_list(argv[2], argv[3])); 372 } 373 374 if (argc > 2 && !strcmp(argv[1], "find-cd")) { 375 g_loglevel = 10; 376 g_text_mode = TRUE; 377 setup_newt_stuff(); 378 if (find_cdrw_device(tmp)) { 379 printf("Failed to find CDR-RW drive\n"); 380 } else { 381 printf("CD-RW is at %s\n", tmp); 382 } 383 tmp[0] = '\0'; 384 if (find_cdrom_device(tmp, atoi(argv[2]))) { 385 printf("Failed to find CD-ROM drive\n"); 386 } else { 387 printf("CD-ROM is at %s\n", tmp); 388 } 389 finish(0); 390 } 391 392 if (argc > 2 && !strcmp(argv[1], "find-dvd")) { 393 g_loglevel = 10; 394 g_text_mode = TRUE; 395 setup_newt_stuff(); 396 if (find_dvd_device(tmp, atoi(argv[2]))) { 397 printf("Failed to find DVD drive\n"); 398 } else { 399 printf("DVD is at %s\n", tmp); 400 } 401 finish(0); 402 } 403 404 if (argc > 2 && !strcmp(argv[1], "disksize")) { 405 printf("%s --> %ld\n", argv[2], get_phys_size_of_drive(argv[2])); 406 finish(0); 407 } 408 if (argc > 2 && !strcmp(argv[1], "test-dev")) { 409 if (is_dev_an_NTFS_dev(argv[2])) { 410 printf("%s is indeed an NTFS dev\n", argv[2]); 411 } else { 412 printf("%s is _not_ an NTFS dev\n", argv[2]); 413 } 414 finish(0); 415 } 416 417 if (pre_param_configuration(bkpinfo)) { 418 fatal_error 419 ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting..."); 420 } 421 411 422 /* Process command line, if there is one. If not, ask user for info. */ 412 if (argc==1) 413 { 414 g_text_mode = FALSE; 415 setup_newt_stuff (); 416 res = interactively_obtain_media_parameters_from_user(bkpinfo, TRUE); /* yes, archiving */ 417 if (res) { fatal_error("Syntax error. Please review the parameters you have supplied and try again."); } 418 } 419 else 420 { 421 res = handle_incoming_parameters (argc, argv, bkpinfo); 422 if (res) { 423 printf("Errors were detected in the command line you supplied.\n"); 424 printf("Please review the log file - " MONDO_LOGFILE "\n"); 425 log_msg(1, "Mondoarchive will now exit."); 426 finish(1); 427 } 428 setup_newt_stuff (); 429 } 423 if (argc == 1) { 424 g_text_mode = FALSE; 425 setup_newt_stuff(); 426 res = interactively_obtain_media_parameters_from_user(bkpinfo, TRUE); /* yes, archiving */ 427 if (res) { 428 fatal_error 429 ("Syntax error. Please review the parameters you have supplied and try again."); 430 } 431 } else { 432 res = handle_incoming_parameters(argc, argv, bkpinfo); 433 if (res) { 434 printf 435 ("Errors were detected in the command line you supplied.\n"); 436 printf("Please review the log file - " MONDO_LOGFILE "\n"); 437 log_msg(1, "Mondoarchive will now exit."); 438 finish(1); 439 } 440 setup_newt_stuff(); 441 } 430 442 431 443 /* Finish configuring global structures */ 432 if (post_param_configuration (bkpinfo)) { fatal_error("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting..."); } 433 434 log_to_screen("BusyBox's sources are available from http://www.busybox.net"); 435 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir); 436 437 /* If we're meant to backup then backup */ 438 if (bkpinfo->backup_data) 439 { 444 if (post_param_configuration(bkpinfo)) { 445 fatal_error 446 ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting..."); 447 } 448 449 log_to_screen 450 ("BusyBox's sources are available from http://www.busybox.net"); 451 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, 452 bkpinfo->scratchdir); 453 454 /* If we're meant to backup then backup */ 455 if (bkpinfo->backup_data) { 440 456 /* 441 457 log_to_screen("INFERNAL PORPOISES"); … … 444 460 finish(0); 445 461 */ 446 res = backup_data(bkpinfo); 447 retval += res; 448 if (res) 449 { strcat (say_at_end, "Data archived. Please check the logs, just as a precaution. "); } 450 else 451 { strcat (say_at_end, "Data archived OK. "); } 452 } 462 res = backup_data(bkpinfo); 463 retval += res; 464 if (res) { 465 strcat(say_at_end, 466 "Data archived. Please check the logs, just as a precaution. "); 467 } else { 468 strcat(say_at_end, "Data archived OK. "); 469 } 470 } 453 471 454 472 /* If we're meant to verify then verify */ 455 if (bkpinfo->verify_data) 456 { 457 res = verify_data(bkpinfo); 458 if (res<0) 459 { 460 sprintf(tmp, "%d difference%c found.", -res, (-res != 1) ? 's' : ' '); 461 strcat(say_at_end, tmp); 462 log_to_screen(tmp); 463 res=0; 464 } 465 retval += res; 466 } 473 if (bkpinfo->verify_data) { 474 res = verify_data(bkpinfo); 475 if (res < 0) { 476 sprintf(tmp, "%d difference%c found.", -res, 477 (-res != 1) ? 's' : ' '); 478 strcat(say_at_end, tmp); 479 log_to_screen(tmp); 480 res = 0; 481 } 482 retval += res; 483 } 467 484 468 485 /* Offer to write floppy disk images to physical disks */ 469 if (bkpinfo->backup_data && !g_skip_floppies) 470 { 471 res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo); 472 retval += res; 486 if (bkpinfo->backup_data && !g_skip_floppies) { 487 res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo); 488 retval += res; 473 489 // res = offer_to_write_boot_ISO_to_physical_CD(bkpinfo); 474 490 // retval += res; 475 491 } 476 492 477 493 /* Report result of entire operation (success? errors?) */ 478 if (!retval) 479 { 480 mvaddstr_and_log_it (g_currentY++, 0, 481 "Backup and/or verify ran to completion. Everything appears to be fine."); 482 } 483 else 484 { 485 mvaddstr_and_log_it (g_currentY++, 0, 486 "Backup and/or verify ran to completion. However, errors did occur."); 487 } 488 489 if (does_file_exist ("/root/images/mindi/mondorescue.iso")) 490 { 491 log_to_screen ("/root/images/mindi/mondorescue.iso, a boot/utility CD, is available if you want it."); 492 } 493 494 495 if (length_of_file ("/tmp/changed.files") > 2) 496 { 497 if (g_text_mode) { log_to_screen("Type 'less /tmp/changed.files' to see which files don't match the archives"); } 498 else 499 { 500 log_msg (1, "Type 'less /tmp/changed.files' to see which files don't match the archives"); 501 log_msg (2, "Calling popup_changelist_from_file()"); 502 popup_changelist_from_file("/tmp/changed.files"); 503 log_msg (2, "Returned from popup_changelist_from_file()"); 504 } 505 } 506 else 507 { 508 unlink ("/tmp/changed.files"); 509 } 510 log_to_screen (say_at_end); 511 sprintf (tmp, "umount %s/tmpfs", bkpinfo->tmpdir); 512 run_program_and_log_output (tmp, TRUE); 513 run_program_and_log_output (g_erase_tmpdir_and_scratchdir, TRUE); 514 515 run_program_and_log_output("mount", 2); 516 517 if (bkpinfo->please_dont_eject) 518 { 519 log_msg(5, "Not ejecting at end. Fair enough."); 520 } 521 else 522 { 523 log_msg(5, "Ejecting at end."); 524 if (!find_cdrom_device(tmp, FALSE) || !find_dvd_device(tmp, FALSE)) 525 { 526 log_msg(1, "Ejecting %s", tmp); 527 eject_device(tmp); 528 } 529 } 530 531 system("rm -f /var/cache/mondo-archive/last-backup.aborted"); 532 system("rm -Rf /tmp.mondo.* /mondo.scratch.*"); 533 if (!retval) { printf("Mondoarchive ran OK.\n"); } 534 else { printf("Errors occurred during backup. Please check logfile.\n"); } 535 distro_specific_kludges_at_end_of_mondoarchive(); 536 register_pid(0,"mondo"); 537 set_signals(FALSE); 538 chdir("/tmp"); // just in case there's something wrong with g_erase_tmpdir_and_scratchdir 539 system(g_erase_tmpdir_and_scratchdir); 540 free_libmondo_global_strings(); 541 paranoid_free(say_at_end); 542 paranoid_free(tmp); 543 paranoid_free(bkpinfo); 544 545 unlink("/tmp/filelist.full"); 546 unlink("/tmp/filelist.full.gz"); 547 548 if (!g_cdrom_drive_is_here) { log_msg(10, "FYI, g_cdrom_drive_is_here was never used"); } 549 if (!g_dvd_drive_is_here) { log_msg(10, "FYI, g_dvd_drive_is_here was never used"); } 550 551 if (!g_text_mode) 552 { 553 popup_and_OK 554 ("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt."); 555 log_to_screen("See %s for details of backup run.", MONDO_LOGFILE); 556 finish(retval); 557 } 558 else 559 { 560 printf ("See %s for details of backup run.\n", MONDO_LOGFILE); 561 exit(retval); 562 } 563 564 return EXIT_SUCCESS; 494 if (!retval) { 495 mvaddstr_and_log_it(g_currentY++, 0, 496 "Backup and/or verify ran to completion. Everything appears to be fine."); 497 } else { 498 mvaddstr_and_log_it(g_currentY++, 0, 499 "Backup and/or verify ran to completion. However, errors did occur."); 500 } 501 502 if (does_file_exist("/root/images/mindi/mondorescue.iso")) { 503 log_to_screen 504 ("/root/images/mindi/mondorescue.iso, a boot/utility CD, is available if you want it."); 505 } 506 507 508 if (length_of_file("/tmp/changed.files") > 2) { 509 if (g_text_mode) { 510 log_to_screen 511 ("Type 'less /tmp/changed.files' to see which files don't match the archives"); 512 } else { 513 log_msg(1, 514 "Type 'less /tmp/changed.files' to see which files don't match the archives"); 515 log_msg(2, "Calling popup_changelist_from_file()"); 516 popup_changelist_from_file("/tmp/changed.files"); 517 log_msg(2, "Returned from popup_changelist_from_file()"); 518 } 519 } else { 520 unlink("/tmp/changed.files"); 521 } 522 log_to_screen(say_at_end); 523 sprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir); 524 run_program_and_log_output(tmp, TRUE); 525 run_program_and_log_output(g_erase_tmpdir_and_scratchdir, TRUE); 526 527 run_program_and_log_output("mount", 2); 528 529 if (bkpinfo->please_dont_eject) { 530 log_msg(5, "Not ejecting at end. Fair enough."); 531 } else { 532 log_msg(5, "Ejecting at end."); 533 if (!find_cdrom_device(tmp, FALSE) || !find_dvd_device(tmp, FALSE)) { 534 log_msg(1, "Ejecting %s", tmp); 535 eject_device(tmp); 536 } 537 } 538 539 system("rm -f /var/cache/mondo-archive/last-backup.aborted"); 540 system("rm -Rf /tmp.mondo.* /mondo.scratch.*"); 541 if (!retval) { 542 printf("Mondoarchive ran OK.\n"); 543 } else { 544 printf("Errors occurred during backup. Please check logfile.\n"); 545 } 546 distro_specific_kludges_at_end_of_mondoarchive(); 547 register_pid(0, "mondo"); 548 set_signals(FALSE); 549 chdir("/tmp"); // just in case there's something wrong with g_erase_tmpdir_and_scratchdir 550 system(g_erase_tmpdir_and_scratchdir); 551 free_libmondo_global_strings(); 552 paranoid_free(say_at_end); 553 paranoid_free(tmp); 554 paranoid_free(bkpinfo); 555 556 unlink("/tmp/filelist.full"); 557 unlink("/tmp/filelist.full.gz"); 558 559 if (!g_cdrom_drive_is_here) { 560 log_msg(10, "FYI, g_cdrom_drive_is_here was never used"); 561 } 562 if (!g_dvd_drive_is_here) { 563 log_msg(10, "FYI, g_dvd_drive_is_here was never used"); 564 } 565 566 if (!g_text_mode) { 567 popup_and_OK 568 ("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt."); 569 log_to_screen("See %s for details of backup run.", MONDO_LOGFILE); 570 finish(retval); 571 } else { 572 printf("See %s for details of backup run.\n", MONDO_LOGFILE); 573 exit(retval); 574 } 575 576 return EXIT_SUCCESS; 565 577 } 566 567 -
trunk/mondo/mondo/mondoarchive/mondo-cli-EXT.h
r30 r59 1 1 /* mondo-cli-EXT.h */ 2 2 3 extern int handle_incoming_parameters (int argc, char *argv[], struct s_bkpinfo *bkpinfo); 3 extern int handle_incoming_parameters(int argc, char *argv[], 4 struct s_bkpinfo *bkpinfo); 4 5 extern int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value); 5 extern int process_switches (struct s_bkpinfo *bkpinfo, char flag_val[128][MAX_STR_LEN], 6 bool flag_set[128]); 7 extern int retrieve_switches_from_command_line (int argc, char *argv[], 8 char flag_val[128][MAX_STR_LEN], 9 bool flag_set[128]); 10 extern void help_screen (); 6 extern int process_switches(struct s_bkpinfo *bkpinfo, 7 char flag_val[128][MAX_STR_LEN], 8 bool flag_set[128]); 9 extern int retrieve_switches_from_command_line(int argc, char *argv[], 10 char 11 flag_val[128][MAX_STR_LEN], 12 bool flag_set[128]); 13 extern void help_screen(); 11 14 extern void terminate_daemon(int sig); 12 15 extern void set_signals(int on); 13 16 extern void termination_in_progress(int sig); 14 -
trunk/mondo/mondo/mondoarchive/mondo-cli.c
r30 r59 7 7 edited by : by Stan Benoit 4/2002 8 8 email : troff@nakedsoul.org 9 cvsid : $Id : mondo-cli.c,v 1.11 2004/06/21 20:20:36 hugo Exp$9 cvsid : $Id$ 10 10 ***************************************************************************/ 11 11 … … 175 175 176 176 177 //static char cvsid[] = "$Id : mondo-cli.c,v 1.11 2004/06/21 20:20:36 hugo Exp$";177 //static char cvsid[] = "$Id$"; 178 178 179 179 extern int g_loglevel; 180 180 extern bool g_text_mode; 181 extern bool g_skip_floppies; 182 extern char g_startdir[MAX_STR_LEN]; 181 extern bool g_skip_floppies; ///< Whether to skip the creation of boot disks 182 extern char g_startdir[MAX_STR_LEN]; ///< ????? @bug ????? 183 183 extern char g_erase_tmpdir_and_scratchdir[MAX_STR_LEN]; 184 184 extern char g_tmpfs_mountpt[MAX_STR_LEN]; … … 195 195 196 196 /*@ bool******** **************************************************/ 197 bool g_debugging = FALSE; 198 bool g_running_live = FALSE; 197 bool g_debugging = FALSE; ///< ????? @bug ????? @ingroup globalGroup 198 bool g_running_live = FALSE; ///< ????? @bug ????? @ingroup globalGroup 199 199 extern bool g_cd_recovery; 200 200 … … 220 220 221 221 222 extern char *resolve_softlinks_to_get_to_actual_device_file(char*);222 extern char *resolve_softlinks_to_get_to_actual_device_file(char *); 223 223 224 224 … … 236 236 */ 237 237 int 238 handle_incoming_parameters (int argc, char *argv[], struct s_bkpinfo *bkpinfo) 238 handle_incoming_parameters(int argc, char *argv[], 239 struct s_bkpinfo *bkpinfo) 239 240 { 240 /*@ int ****/ 241 int res = 0; 242 int retval = 0; 243 int i = 0, j; 244 245 /*@ buffers ****************/ 246 char *tmp; 247 char flag_val[128][MAX_STR_LEN]; 248 bool flag_set[128]; 249 250 malloc_string(tmp); 251 sensibly_set_tmpdir_and_scratchdir(bkpinfo); 252 for (i = 0; i < 128; i++) 253 { 254 flag_val[i][0] = '\0'; 255 flag_set[i] = FALSE; 256 } 257 // strcpy (bkpinfo->tmpdir, "/root/images/mondo"); 258 // strcpy (bkpinfo->scratchdir, "/home"); 259 for(j=1; j<=MAX_NOOF_MEDIA; j++) {bkpinfo->media_size[j] = 650;} /* default */ 260 res = retrieve_switches_from_command_line (argc, argv, flag_val, flag_set); 261 retval += res; 262 if (!retval) 263 { 264 res = process_switches (bkpinfo, flag_val, flag_set); 265 retval += res; 266 } 241 /*@ int *** */ 242 int res = 0; 243 int retval = 0; 244 int i = 0, j; 245 246 /*@ buffers *************** */ 247 char *tmp; 248 char flag_val[128][MAX_STR_LEN]; 249 bool flag_set[128]; 250 251 malloc_string(tmp); 252 sensibly_set_tmpdir_and_scratchdir(bkpinfo); 253 for (i = 0; i < 128; i++) { 254 flag_val[i][0] = '\0'; 255 flag_set[i] = FALSE; 256 } 257 // strcpy (bkpinfo->tmpdir, "/root/images/mondo"); 258 // strcpy (bkpinfo->scratchdir, "/home"); 259 for (j = 1; j <= MAX_NOOF_MEDIA; j++) { 260 bkpinfo->media_size[j] = 650; 261 } /* default */ 262 res = 263 retrieve_switches_from_command_line(argc, argv, flag_val, 264 flag_set); 265 retval += res; 266 if (!retval) { 267 res = process_switches(bkpinfo, flag_val, flag_set); 268 retval += res; 269 } 267 270 /* 268 271 if (!retval) 269 272 { 270 273 */ 271 log_msg (3, "Switches:-"); 272 for (i = 0; i < 128; i++) 273 { 274 if (flag_set[i]) 275 { 276 sprintf (tmp, "-%c %s", i, flag_val[i]); 277 log_msg (3, tmp); 278 } 274 log_msg(3, "Switches:-"); 275 for (i = 0; i < 128; i++) { 276 if (flag_set[i]) { 277 sprintf(tmp, "-%c %s", i, flag_val[i]); 278 log_msg(3, tmp); 279 } 279 280 } 280 281 // } 281 sprintf (tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir); 282 paranoid_system (tmp); 283 sprintf (tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir); 284 paranoid_system (tmp); 285 sprintf (bkpinfo->tmpdir + strlen (bkpinfo->tmpdir), "/tmp.mondo.%ld", 286 random () % 32767); 287 sprintf (bkpinfo->scratchdir + strlen (bkpinfo->scratchdir), 288 "/mondo.scratch.%ld", random () % 32767); 289 sprintf (tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 290 paranoid_system (tmp); 291 sprintf (tmp, "mkdir -p %s", bkpinfo->scratchdir); 292 paranoid_system (tmp); 293 if (bkpinfo->nfs_mount[0] != '\0') 294 { 295 store_nfs_config (bkpinfo); 296 } 297 paranoid_free(tmp); 298 return (retval); 282 sprintf(tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir); 283 paranoid_system(tmp); 284 sprintf(tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir); 285 paranoid_system(tmp); 286 sprintf(bkpinfo->tmpdir + strlen(bkpinfo->tmpdir), "/tmp.mondo.%ld", 287 random() % 32767); 288 sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir), 289 "/mondo.scratch.%ld", random() % 32767); 290 sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 291 paranoid_system(tmp); 292 sprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir); 293 paranoid_system(tmp); 294 if (bkpinfo->nfs_mount[0] != '\0') { 295 store_nfs_config(bkpinfo); 296 } 297 paranoid_free(tmp); 298 return (retval); 299 299 } 300 300 … … 311 311 int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value) 312 312 { 313 314 315 316 assert(bkpinfo!=NULL);317 assert(value!=NULL);318 319 bkpinfo->media_size[0] = -1;/* dummy value */320 for(j=1, p=value; j<MAX_NOOF_MEDIA && strchr(p,','); j++, p=strchr(p,',')+1) 321 {322 323 *(strchr(tmp,',')) = '\0';324 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp);325 sprintf(comment, "media_size[%d] = %ld", j, bkpinfo->media_size[j]); 326 log_msg(3, comment);327 }328 for(; j<=MAX_NOOF_MEDIA; j++) 329 {330 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p);313 int j; 314 char tmp[MAX_STR_LEN], *p, comment[MAX_STR_LEN]; 315 316 assert(bkpinfo != NULL); 317 assert(value != NULL); 318 319 bkpinfo->media_size[0] = -1; /* dummy value */ 320 for (j = 1, p = value; j < MAX_NOOF_MEDIA && strchr(p, ','); 321 j++, p = strchr(p, ',') + 1) { 322 strncpy(tmp, p, MAX_STR_LEN); 323 *(strchr(tmp, ',')) = '\0'; 324 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp); 325 sprintf(comment, "media_size[%d] = %ld", j, 326 bkpinfo->media_size[j]); 327 log_msg(3, comment); 328 } 329 for (; j <= MAX_NOOF_MEDIA; j++) { 330 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p); 331 331 } 332 332 // bkpinfo->media_size[0] = bkpinfo->media_size[MAX_NOOF_MEDIA]; 333 for(j=1; j<=MAX_NOOF_MEDIA; j++) 334 { 335 if (bkpinfo->media_size[j]<=0) { log_msg(1, "You gave media #%d an invalid size\n", j); return(-1); } 336 } 337 return(0); 333 for (j = 1; j <= MAX_NOOF_MEDIA; j++) { 334 if (bkpinfo->media_size[j] <= 0) { 335 log_msg(1, "You gave media #%d an invalid size\n", j); 336 return (-1); 337 } 338 } 339 return (0); 338 340 } 339 341 … … 351 353 */ 352 354 int 353 process_switches (struct s_bkpinfo *bkpinfo, char flag_val[128][MAX_STR_LEN],354 355 process_switches(struct s_bkpinfo *bkpinfo, 356 char flag_val[128][MAX_STR_LEN], bool flag_set[128]) 355 357 { 356 358 357 /*@ ints *** */358 359 360 361 362 /*@ buffers ** */363 364 365 366 367 368 369 370 371 assert(bkpinfo!=NULL);372 assert(flag_val!=NULL);373 assert(flag_set!=NULL);374 375 359 /*@ ints *** */ 360 int i = 0; 361 int retval = 0; 362 int percent = 0; 363 364 /*@ buffers ** */ 365 char *tmp; 366 char *psz; 367 368 long itbs; 369 370 malloc_string(tmp); 371 malloc_string(psz); 372 373 assert(bkpinfo != NULL); 374 assert(flag_val != NULL); 375 assert(flag_set != NULL); 376 377 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 376 378 377 379 /* compulsory */ 378 i = 379 flag_set['c'] + flag_set['i'] + flag_set['n'] + 380 flag_set['t'] + flag_set['u'] + flag_set['r'] + 381 flag_set['w'] + flag_set['C']; 382 if (i == 0) 383 { 384 retval++; 385 log_to_screen( "You must specify the media type\n"); 386 } 387 if (i > 1) 388 { 389 retval++; 390 log_to_screen( "Please specify only one media type\n"); 391 } 392 if (flag_set['K']) 393 { 394 g_loglevel = atoi(flag_val['K']); 395 if (g_loglevel < 3) { g_loglevel = 3; } 396 } 397 if (flag_set['L'] && flag_set['0']) 398 { 399 retval++; 400 log_to_screen( "You cannot have 'no compression' _and_ LZOP.\n"); 401 } 402 bkpinfo->backup_data = flag_set['O']; 403 bkpinfo->verify_data = flag_set['V']; 404 if (flag_set['I'] && !bkpinfo->backup_data) 405 { 406 log_to_screen ("-I switch is ignored if just verifying"); 407 } 408 if (flag_set['E'] && !bkpinfo->backup_data) 409 { 410 log_to_screen ("-E switch is ignored if just verifying"); 411 } 412 413 if (!find_home_of_exe("afio")) 414 { 415 if (find_home_of_exe("star")) 380 i = flag_set['c'] + flag_set['i'] + flag_set['n'] + 381 flag_set['t'] + flag_set['u'] + flag_set['r'] + 382 flag_set['w'] + flag_set['C']; 383 if (i == 0) { 384 retval++; 385 log_to_screen("You must specify the media type\n"); 386 } 387 if (i > 1) { 388 retval++; 389 log_to_screen("Please specify only one media type\n"); 390 } 391 if (flag_set['K']) { 392 g_loglevel = atoi(flag_val['K']); 393 if (g_loglevel < 3) { 394 g_loglevel = 3; 395 } 396 } 397 if (flag_set['L'] && flag_set['0']) { 398 retval++; 399 log_to_screen("You cannot have 'no compression' _and_ LZOP.\n"); 400 } 401 bkpinfo->backup_data = flag_set['O']; 402 bkpinfo->verify_data = flag_set['V']; 403 if (flag_set['I'] && !bkpinfo->backup_data) { 404 log_to_screen("-I switch is ignored if just verifying"); 405 } 406 if (flag_set['E'] && !bkpinfo->backup_data) { 407 log_to_screen("-E switch is ignored if just verifying"); 408 } 409 410 if (!find_home_of_exe("afio")) { 411 if (find_home_of_exe("star")) { 412 flag_set['R'] = TRUE; 413 log_msg(1, "Using star instead of afio"); 414 } else { 415 fatal_error 416 ("Neither afio nor star is installed. Please install at least one."); 417 } 418 } 419 420 if (flag_set['R']) { 421 bkpinfo->use_star = TRUE; 422 if (flag_set['L']) { 423 fatal_error("You may not use star and lzop at the same time."); 424 } 425 if (!find_home_of_exe("star")) { 426 fatal_error 427 ("Please install 'star' RPM or tarball if you are going to use -R. Thanks."); 428 } 429 } 430 if (flag_set['W']) { 431 bkpinfo->nonbootable_backup = TRUE; 432 log_to_screen("Warning - you have opted for non-bootable backup"); 433 if (flag_set['f'] || flag_set['l']) { 434 log_to_screen 435 ("You don't need to specify bootloader or bootdevice"); 436 } 437 } 438 if (flag_set['t'] && flag_set['H']) { 439 fatal_error 440 ("Sorry, you may not nuke w/o warning from tape. Drop -H, please."); 441 } 442 if (flag_set['I']) { 443 if (!strcmp(bkpinfo->include_paths, "/")) { 444 log_msg(2, "'/' is pleonastic."); 445 bkpinfo->include_paths[0] = '\0'; 446 } 447 if (bkpinfo->include_paths[0]) { 448 strcat(bkpinfo->include_paths, " "); 449 } 450 strncpy(bkpinfo->include_paths + strlen(bkpinfo->include_paths), 451 flag_val['I'], 452 MAX_STR_LEN - strlen(bkpinfo->include_paths)); 453 log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths); 454 if (bkpinfo->include_paths[0] == '-') { 455 retval++; 456 log_to_screen("Please supply a sensible value with '-I'\n"); 457 } 458 } 459 460 if (g_kernel_version >= 2.6 && !flag_set['d'] 461 && (flag_set['c'] || flag_set['w'])) { 462 fatal_error 463 ("If you are using the 2.6.x kernel, please specify the CD-R(W) device."); 464 } 465 466 467 if (flag_set['J']) { 468 if (flag_set['I']) { 469 retval++; 470 log_to_screen 471 ("Please do not use -J in combination with -I. If you want to make a list of files to backup, that's fine, use -J <filename> but please don't muddy the waters by combining -J with -I. Thanks. :-)"); 472 } 473 bkpinfo->make_filelist = FALSE; 474 strcpy(bkpinfo->include_paths, flag_val['J']); 475 } 476 if (flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) { 477 if (!flag_set['r'] && g_kernel_version <= 2.5 478 && strstr(flag_val['d'], "/dev/")) { 479 fatal_error 480 ("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag."); 481 } 482 if (flag_set['r'] && g_kernel_version <= 2.5 483 && !strstr(flag_val['d'], "/dev/")) { 484 fatal_error 485 ("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag."); 486 } 487 if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) { 488 log_to_screen 489 ("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk..."); 490 } 491 492 if (system("which cdrecord > /dev/null 2> /dev/null") 493 && system("which dvdrecord > /dev/null 2> /dev/null")) { 494 fatal_error 495 ("Please install dvdrecord/cdrecord and try again."); 496 } 497 if (flag_set['C']) { 498 bkpinfo->cdrw_speed = 2; 499 if (!flag_set['L']) { 500 log_to_screen 501 ("You must use -L with -C. Therefore I am setting it for you."); 502 flag_set['L'] = 1; 503 flag_val['L'][0] = '\0'; 504 } 505 } else { 506 log_msg(3, "flag_val['c'] = %s", flag_val['c']); 507 log_msg(3, "flag_val['w'] = %s", flag_val['w']); 508 // log_msg(3, "flag_set['r'] = %i", flag_set['r'] ); 509 if (flag_set['c']) { 510 bkpinfo->cdrw_speed = atoi(flag_val['c']); 511 } else if (flag_set['w']) { 512 bkpinfo->cdrw_speed = atoi(flag_val['w']); 513 } else if (flag_set['r']) { 514 bkpinfo->cdrw_speed = 1; /*atoi(flag_val['r']); */ 515 } 516 517 if (bkpinfo->cdrw_speed < 1) { 518 fatal_error 519 ("You specified a silly speed for a CD-R[W] drive"); 520 } 521 } 522 } 523 if (flag_set['t'] && !flag_set['d']) { 524 log_it("Hmm! No tape drive specified. Let's see what we can do."); 525 if (find_tape_device_and_size(flag_val['d'], tmp)) { 526 fatal_error 527 ("Tape device not specified. I couldn't find it either."); 528 } 529 flag_set['d'] = TRUE; 530 sprintf(tmp, 531 "You didn't specify a tape streamer device. I'm assuming %s", 532 flag_val['d']); 533 log_to_screen(tmp); 534 percent = 0; 535 } 536 537 if (flag_set['r']) // DVD 416 538 { 417 flag_set['R'] = TRUE; 418 log_msg(1, "Using star instead of afio"); 419 } 420 else 421 { 422 fatal_error("Neither afio nor star is installed. Please install at least one."); 423 } 424 } 425 426 if (flag_set['R']) 427 { 428 bkpinfo->use_star = TRUE; 429 if (flag_set['L']) 430 { fatal_error ("You may not use star and lzop at the same time."); } 431 if (!find_home_of_exe("star")) 432 { fatal_error ("Please install 'star' RPM or tarball if you are going to use -R. Thanks."); } 433 } 434 if (flag_set['W']) 435 { 436 bkpinfo->nonbootable_backup = TRUE; 437 log_to_screen ("Warning - you have opted for non-bootable backup"); 438 if (flag_set['f'] || flag_set['l']) 439 { 440 log_to_screen ("You don't need to specify bootloader or bootdevice"); 441 } 442 } 443 if (flag_set['t'] && flag_set['H']) 444 { fatal_error("Sorry, you may not nuke w/o warning from tape. Drop -H, please."); } 445 if (flag_set['I']) 446 { 447 if (!strcmp(bkpinfo->include_paths, "/")) 448 { 449 log_msg(2, "'/' is pleonastic."); 450 bkpinfo->include_paths[0] = '\0'; 451 } 452 if (bkpinfo->include_paths[0]) 453 { strcat(bkpinfo->include_paths," "); } 454 strncpy (bkpinfo->include_paths+strlen(bkpinfo->include_paths), flag_val['I'], MAX_STR_LEN - strlen(bkpinfo->include_paths)); 455 log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths); 456 if (bkpinfo->include_paths[0] == '-') 457 { 458 retval++; 459 log_to_screen( "Please supply a sensible value with '-I'\n"); 460 } 461 } 462 463 if (g_kernel_version >= 2.6 && !flag_set['d'] && (flag_set['c'] || flag_set['w'])) 464 { 465 fatal_error("If you are using the 2.6.x kernel, please specify the CD-R(W) device."); 466 } 467 468 469 if (flag_set['J']) 470 { 471 if (flag_set['I']) 472 { 473 retval++; 474 log_to_screen( "Please do not use -J in combination with -I. If you want to make a list of files to backup, that's fine, use -J <filename> but please don't muddy the waters by combining -J with -I. Thanks. :-)"); 475 } 476 bkpinfo->make_filelist = FALSE; 477 strcpy(bkpinfo->include_paths, flag_val['J']); 478 } 479 if (flag_set['c'] || flag_set['w'] || flag_set['C'] || flag_set['r']) 480 { 481 if (!flag_set['r'] && g_kernel_version <= 2.5 && strstr(flag_val['d'], "/dev/")) 482 { fatal_error("Please don't give a /dev entry. Give a SCSI node for the parameter of the -d flag."); } 483 if (flag_set['r'] && g_kernel_version <= 2.5 && !strstr(flag_val['d'], "/dev/")) 484 { fatal_error("Please give a /dev entry, not a SCSI node, as the parameter of the -d flag."); } 485 if (g_kernel_version >= 2.6 && !strstr(flag_val['d'], "/dev/")) 486 { log_to_screen("Linus says 2.6 has a broken ide-scsi module. Proceed at your own risk..."); } 487 488 if (system ("which cdrecord > /dev/null 2> /dev/null") && system("which dvdrecord > /dev/null 2> /dev/null")) 489 { 490 fatal_error ("Please install dvdrecord/cdrecord and try again."); 491 } 492 if (flag_set['C']) 493 { 494 bkpinfo->cdrw_speed = 2; 495 if (!flag_set['L']) 496 { 497 log_to_screen ("You must use -L with -C. Therefore I am setting it for you."); 498 flag_set['L'] = 1; 499 flag_val['L'][0] = '\0'; 500 } 501 } 502 else 503 { 504 log_msg(3, "flag_val['c'] = %s", flag_val['c'] ); 505 log_msg(3, "flag_val['w'] = %s", flag_val['w'] ); 506 // log_msg(3, "flag_set['r'] = %i", flag_set['r'] ); 507 if (flag_set['c']) { bkpinfo->cdrw_speed = atoi(flag_val['c']); } 508 else 509 if (flag_set['w']) { bkpinfo->cdrw_speed = atoi(flag_val['w']); } 510 else 511 if (flag_set['r']) { bkpinfo->cdrw_speed = 1; /*atoi(flag_val['r']);*/ } 512 513 if (bkpinfo->cdrw_speed < 1) 514 { 515 fatal_error ("You specified a silly speed for a CD-R[W] drive"); 516 } 517 } 518 } 519 if (flag_set['t'] && !flag_set['d']) 520 { 521 log_it("Hmm! No tape drive specified. Let's see what we can do."); 522 if (find_tape_device_and_size(flag_val['d'], tmp)) 523 { fatal_error("Tape device not specified. I couldn't find it either."); } 524 flag_set['d'] = TRUE; 525 sprintf(tmp, "You didn't specify a tape streamer device. I'm assuming %s", flag_val['d']); 526 log_to_screen(tmp); 527 percent = 0; 528 } 529 530 if (flag_set['r']) // DVD 531 { 532 if (flag_set['m']) 533 { fatal_error("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m."); } 534 if (!flag_set['d']) 535 { 536 if (!find_dvd_device(flag_val['d'], FALSE)) 537 { 538 flag_set['d'] = TRUE; 539 log_to_screen("I guess DVD drive is at %s", flag_val['d']); 540 } 541 } 542 if (!find_home_of_exe("growisofs")) 543 { fatal_error("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it."); } 544 if (!find_home_of_exe("dvd+rw-format")) 545 { fatal_error("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it."); } 546 if (strchr(flag_val['d'], ',')) 547 { fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); } 548 if (!flag_set['s']) 549 { 550 sprintf (flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 551 strcat ( flag_val['s'], "m"); 552 log_to_screen ("You did not specify a size (-s) for DVD. I'm guessing %s.", flag_val['s']); 553 flag_set['s'] = 1; 554 } 539 if (flag_set['m']) { 540 fatal_error 541 ("Manual CD tray (-m) not yet supported in conjunction w/ DVD drives. Drop -m."); 542 } 543 if (!flag_set['d']) { 544 if (!find_dvd_device(flag_val['d'], FALSE)) { 545 flag_set['d'] = TRUE; 546 log_to_screen("I guess DVD drive is at %s", flag_val['d']); 547 } 548 } 549 if (!find_home_of_exe("growisofs")) { 550 fatal_error 551 ("Please install growisofs (probably part of dvd+rw-tools). If you want DVD support, you need it."); 552 } 553 if (!find_home_of_exe("dvd+rw-format")) { 554 fatal_error 555 ("Please install dvd+rw-format (probably part of dvd+rw-tools). If you want DVD support, you need it."); 556 } 557 if (strchr(flag_val['d'], ',')) { 558 fatal_error 559 ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); 560 } 561 if (!flag_set['s']) { 562 sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB 563 strcat(flag_val['s'], "m"); 564 log_to_screen 565 ("You did not specify a size (-s) for DVD. I'm guessing %s.", 566 flag_val['s']); 567 flag_set['s'] = 1; 568 } 555 569 /* 556 570 if (flag_set['Z']) { … … 558 572 } 559 573 */ 560 } 561 562 if (flag_set['t'] || flag_set['u']) 563 { /* tape size */ 564 if (strchr(flag_val['d'], ',')) 565 { fatal_error("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); } 566 if (flag_set['O']) 574 } 575 576 if (flag_set['t'] || flag_set['u']) { /* tape size */ 577 if (strchr(flag_val['d'], ',')) { 578 fatal_error 579 ("Please don't give a SCSI node. Give a _device_, preferably a /dev entry, for the parameter of the -d flag."); 580 } 581 if (flag_set['O']) { 582 if (flag_set['s']) { 583 if (flag_set['t']) { 584 fatal_error 585 ("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway."); 586 } 587 if (process_the_s_switch(bkpinfo, flag_val['s'])) { 588 fatal_error("Bad -s switch"); 589 } 590 } else if (flag_set['u'] || flag_set['t']) { 591 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 592 bkpinfo->media_size[i] = 0; 593 } 594 } else { 595 retval++; 596 log_to_screen("Tape size not specified.\n"); 597 } 598 } 599 } else { /* CD size */ 600 if (flag_set['s']) { 601 if (process_the_s_switch(bkpinfo, flag_val['s'])) { 602 fatal_error("Bad -s switch"); 603 } 604 } 605 if (flag_set['w']) { 606 bkpinfo->wipe_media_first = TRUE; 607 } /* CD-RW */ 608 } 609 if (flag_set['n']) { 610 strncpy(bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN); 611 if (!flag_set['d']) { 612 strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN); 613 } 614 sprintf(tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3", 615 bkpinfo->nfs_mount); 616 strncpy(bkpinfo->isodir, 617 call_program_and_get_last_line_of_output(tmp), 618 MAX_STR_LEN / 4); 619 if (strlen(bkpinfo->isodir) < 3) { 620 retval++; 621 log_to_screen("NFS share is not mounted. Please mount it.\n"); 622 } 623 log_msg(3, "mount = %s", bkpinfo->nfs_mount); 624 log_msg(3, "isodir= %s", bkpinfo->isodir); 625 } 626 if (flag_set['c']) { 627 bkpinfo->backup_media_type = cdr; 628 } 629 if (flag_set['C']) { 630 bkpinfo->backup_media_type = cdstream; 631 } 632 if (flag_set['i']) { 633 bkpinfo->backup_media_type = iso; 634 } 635 if (flag_set['n']) { 636 bkpinfo->backup_media_type = nfs; 637 } 638 if (flag_set['r']) { 639 bkpinfo->backup_media_type = dvd; 640 } 641 if (flag_set['t']) { 642 bkpinfo->backup_media_type = tape; 643 } 644 if (flag_set['u']) { 645 bkpinfo->backup_media_type = udev; 646 } 647 if (flag_set['w']) { 648 bkpinfo->backup_media_type = cdrw; 649 } 650 651 /* optional, popular */ 652 if (flag_set['g']) { 653 g_text_mode = FALSE; 654 } 655 if (flag_set['E']) { 656 if (bkpinfo->exclude_paths[0]) { 657 strcat(bkpinfo->exclude_paths, " "); 658 } 659 strncpy(bkpinfo->exclude_paths + strlen(bkpinfo->exclude_paths), 660 flag_val['E'], 661 MAX_STR_LEN - strlen(bkpinfo->exclude_paths)); 662 } 663 if (flag_set['e']) { 664 bkpinfo->please_dont_eject = TRUE; 665 } 666 if (flag_set['N']) // exclude NFS mounts & devices 567 667 { 568 if (flag_set['s'])569 {570 if (flag_set['t']) { fatal_error("For the moment, please don't specify a tape size. Mondo should handle end-of-tape gracefully anyway."); }571 if (process_the_s_switch(bkpinfo, flag_val['s'])) {fatal_error("Bad -s switch");}572 }573 else if (flag_set['u'] || flag_set['t'])574 {575 for(i=0; i<=MAX_NOOF_MEDIA; i++) { bkpinfo->media_size[i] = 0; }576 }577 else578 {579 retval++;580 log_to_screen( "Tape size not specified.\n");581 }582 }583 }584 else585 { /* CD size */586 if (flag_set['s'])587 {588 if (process_the_s_switch(bkpinfo, flag_val['s'])) {fatal_error("Bad -s switch");}589 }590 if (flag_set['w'])591 {592 bkpinfo->wipe_media_first = TRUE;593 } /* CD-RW */594 }595 if (flag_set['n'])596 {597 strncpy (bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN);598 if (!flag_set['d'])599 {600 strncpy (bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN);601 }602 sprintf (tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3",603 bkpinfo->nfs_mount);604 strncpy (bkpinfo->isodir,605 call_program_and_get_last_line_of_output (tmp), MAX_STR_LEN/4);606 if (strlen (bkpinfo->isodir) < 3)607 {608 retval++;609 log_to_screen( "NFS share is not mounted. Please mount it.\n");610 }611 log_msg(3, "mount = %s", bkpinfo->nfs_mount);612 log_msg(3, "isodir= %s", bkpinfo->isodir);613 }614 if (flag_set['c']) { bkpinfo->backup_media_type = cdr; }615 if (flag_set['C']) { bkpinfo->backup_media_type = cdstream; }616 if (flag_set['i']) { bkpinfo->backup_media_type = iso; }617 if (flag_set['n']) { bkpinfo->backup_media_type = nfs; }618 if (flag_set['r']) { bkpinfo->backup_media_type = dvd; }619 if (flag_set['t']) { bkpinfo->backup_media_type = tape; }620 if (flag_set['u']) { bkpinfo->backup_media_type = udev; }621 if (flag_set['w']) { bkpinfo->backup_media_type = cdrw; }622 623 /* optional, popular */624 if (flag_set['g'])625 {626 g_text_mode = FALSE;627 }628 if (flag_set['E'])629 {630 if (bkpinfo->exclude_paths[0])631 { strcat(bkpinfo->exclude_paths," "); }632 strncpy (bkpinfo->exclude_paths+strlen(bkpinfo->exclude_paths), flag_val['E'], MAX_STR_LEN - strlen(bkpinfo->exclude_paths));633 }634 if (flag_set['e'])635 {636 bkpinfo->please_dont_eject = TRUE;637 }638 if (flag_set['N']) // exclude NFS mounts & devices639 {640 668 // strncpy(psz, list_of_NFS_devices_and_mounts(), MAX_STR_LEN); 641 strncpy(psz, list_of_NFS_mounts_only(), MAX_STR_LEN); 642 if (bkpinfo->exclude_paths[0]) { strncat(bkpinfo->exclude_paths, " ", MAX_STR_LEN); } 643 strncat(bkpinfo->exclude_paths, psz, MAX_STR_LEN); 644 log_msg(3, "-N means we're now excluding %s", bkpinfo->exclude_paths); 645 } 646 if (strlen(bkpinfo->exclude_paths) >= MAX_STR_LEN) 647 { 648 fatal_error("Your '-E' parameter is too long. Please use '-J'. (See manual.)"); 649 } 650 if (flag_set['b']) 651 { 652 strcpy(psz, flag_val['b']); 653 log_msg(1, "psz = '%s'", psz); 654 if (psz[strlen(psz)-1] == 'k') 655 { psz[strlen(psz)-1] = '\0'; itbs = atol(psz) * 1024L; } 656 else 657 { itbs = atol(psz); } 658 log_msg(1, "'%s' --> %ld", flag_val['b'], itbs); 659 log_msg(1, "Internal tape block size is now %ld bytes", itbs); 660 if (itbs%512!=0 || itbs < 256 || itbs > 1024L*1024) 661 { fatal_error("Are you nuts? Silly, your internal tape block size is. Abort, I shall."); } 662 bkpinfo->internal_tape_block_size = itbs; 663 } 664 if (flag_set['D']) 665 { 666 bkpinfo->differential = 1; 669 strncpy(psz, list_of_NFS_mounts_only(), MAX_STR_LEN); 670 if (bkpinfo->exclude_paths[0]) { 671 strncat(bkpinfo->exclude_paths, " ", MAX_STR_LEN); 672 } 673 strncat(bkpinfo->exclude_paths, psz, MAX_STR_LEN); 674 log_msg(3, "-N means we're now excluding %s", 675 bkpinfo->exclude_paths); 676 } 677 if (strlen(bkpinfo->exclude_paths) >= MAX_STR_LEN) { 678 fatal_error 679 ("Your '-E' parameter is too long. Please use '-J'. (See manual.)"); 680 } 681 if (flag_set['b']) { 682 strcpy(psz, flag_val['b']); 683 log_msg(1, "psz = '%s'", psz); 684 if (psz[strlen(psz) - 1] == 'k') { 685 psz[strlen(psz) - 1] = '\0'; 686 itbs = atol(psz) * 1024L; 687 } else { 688 itbs = atol(psz); 689 } 690 log_msg(1, "'%s' --> %ld", flag_val['b'], itbs); 691 log_msg(1, "Internal tape block size is now %ld bytes", itbs); 692 if (itbs % 512 != 0 || itbs < 256 || itbs > 1024L * 1024) { 693 fatal_error 694 ("Are you nuts? Silly, your internal tape block size is. Abort, I shall."); 695 } 696 bkpinfo->internal_tape_block_size = itbs; 697 } 698 if (flag_set['D']) { 699 bkpinfo->differential = 1; 667 700 // bkpinfo->differential = atoi (flag_val['D']); 668 if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) 669 { 670 fatal_error ("The D option should be between 1 and 9 inclusive"); 671 } 672 } 673 if (flag_set['x']) 674 { 675 strncpy (bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN/4); 676 if (run_program_and_log_output("which partimagehack", 2)) 677 { fatal_error("Please install partimagehack RPM/tarball."); } 678 } 679 if (flag_set['m']) 680 { 681 bkpinfo->manual_cd_tray = TRUE; 682 } 683 if (flag_set['k']) 684 { 685 strncpy (bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN); 686 if (!strcmp (bkpinfo->kernel_path, "failsafe")) 687 { 688 strcpy (bkpinfo->kernel_path, "FAILSAFE"); 689 } 690 if (strcmp (bkpinfo->kernel_path, "FAILSAFE") 691 && !does_file_exist (bkpinfo->kernel_path)) 692 { 693 retval++; 694 sprintf(tmp, 695 "You specified kernel '%s', which does not exist\n", 696 bkpinfo->kernel_path); 697 log_to_screen(tmp); 698 } 699 } 700 if (flag_set['p']) 701 { 702 strncpy (bkpinfo->prefix, flag_val['p'], MAX_STR_LEN/4); 703 } 704 705 706 if (flag_set['d']) 707 { /* backup directory (if ISO/NFS) */ 708 if (flag_set['i']) 709 { 710 strncpy (bkpinfo->isodir, flag_val['d'], MAX_STR_LEN/4); 711 sprintf(tmp, "ls -l %s", bkpinfo->isodir); 712 if (run_program_and_log_output(tmp, FALSE)) { fatal_error("output folder does not exist - please create it"); } 713 } 714 else if (flag_set['n']) 715 { 716 strncpy (bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN); 717 } 718 else /* backup device (if tape/CD-R/CD-RW) */ 719 { 720 strncpy (bkpinfo->media_device, flag_val['d'], MAX_STR_LEN/4); 721 } 722 } 723 724 if (flag_set['n']) 725 { 726 sprintf (tmp, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir, bkpinfo->nfs_remote_dir); 727 if (run_program_and_log_output (tmp, FALSE)) 728 { 729 retval++; 730 sprintf (tmp, "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n", 731 bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount); 732 log_to_screen (tmp); 733 } 734 } 735 736 if (!flag_set['d'] && (flag_set['c'] || flag_set['w'] || flag_set['C'])) 737 { 738 if (g_kernel_version >= 2.6) 739 { 740 if (popup_and_get_string("Device", "Please specify the device", bkpinfo->media_device, MAX_STR_LEN/4)) 741 { 742 retval ++; 743 log_to_screen("User opted to cancel."); 744 } 745 } 746 else if (find_cdrw_device (bkpinfo->media_device)) 747 { 748 retval++; 749 log_to_screen( 750 "Tried and failed to find CD-R[W] drive automatically.\n"); 751 } 752 else 753 { 754 flag_set['d'] = TRUE; 755 strncpy (flag_val['d'], bkpinfo->media_device, MAX_STR_LEN/4); 756 } 757 } 758 759 if (!flag_set['d'] && !flag_set['n'] && !flag_set['C']) 760 { 761 retval++; 762 log_to_screen( "Please specify the backup device/directory.\n"); 763 fatal_error("You didn't use -d to specify the backup device/directory."); 764 } 701 if ((bkpinfo->differential < 1) || (bkpinfo->differential > 9)) { 702 fatal_error 703 ("The D option should be between 1 and 9 inclusive"); 704 } 705 } 706 if (flag_set['x']) { 707 strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4); 708 if (run_program_and_log_output("which partimagehack", 2)) { 709 fatal_error("Please install partimagehack RPM/tarball."); 710 } 711 } 712 if (flag_set['m']) { 713 bkpinfo->manual_cd_tray = TRUE; 714 } 715 if (flag_set['k']) { 716 strncpy(bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN); 717 if (!strcmp(bkpinfo->kernel_path, "failsafe")) { 718 strcpy(bkpinfo->kernel_path, "FAILSAFE"); 719 } 720 if (strcmp(bkpinfo->kernel_path, "FAILSAFE") 721 && !does_file_exist(bkpinfo->kernel_path)) { 722 retval++; 723 sprintf(tmp, 724 "You specified kernel '%s', which does not exist\n", 725 bkpinfo->kernel_path); 726 log_to_screen(tmp); 727 } 728 } 729 if (flag_set['p']) { 730 strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4); 731 } 732 733 734 if (flag_set['d']) { /* backup directory (if ISO/NFS) */ 735 if (flag_set['i']) { 736 strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4); 737 sprintf(tmp, "ls -l %s", bkpinfo->isodir); 738 if (run_program_and_log_output(tmp, FALSE)) { 739 fatal_error 740 ("output folder does not exist - please create it"); 741 } 742 } else if (flag_set['n']) { 743 strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN); 744 } else { /* backup device (if tape/CD-R/CD-RW) */ 745 746 strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4); 747 } 748 } 749 750 if (flag_set['n']) { 751 sprintf(tmp, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir, 752 bkpinfo->nfs_remote_dir); 753 if (run_program_and_log_output(tmp, FALSE)) { 754 retval++; 755 sprintf(tmp, 756 "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n", 757 bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount); 758 log_to_screen(tmp); 759 } 760 } 761 762 if (!flag_set['d'] 763 && (flag_set['c'] || flag_set['w'] || flag_set['C'])) { 764 if (g_kernel_version >= 2.6) { 765 if (popup_and_get_string 766 ("Device", "Please specify the device", 767 bkpinfo->media_device, MAX_STR_LEN / 4)) { 768 retval++; 769 log_to_screen("User opted to cancel."); 770 } 771 } else if (find_cdrw_device(bkpinfo->media_device)) { 772 retval++; 773 log_to_screen 774 ("Tried and failed to find CD-R[W] drive automatically.\n"); 775 } else { 776 flag_set['d'] = TRUE; 777 strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4); 778 } 779 } 780 781 if (!flag_set['d'] && !flag_set['n'] && !flag_set['C']) { 782 retval++; 783 log_to_screen("Please specify the backup device/directory.\n"); 784 fatal_error 785 ("You didn't use -d to specify the backup device/directory."); 786 } 765 787 /* optional, obscure */ 766 for (i = '0'; i <= '9'; i++) 767 { 768 if (flag_set[i]) 769 { 770 bkpinfo->compression_level = i - '0'; 771 } /* not '\0' but '0' */ 772 } 773 if (flag_set['S']) 774 { 775 sprintf (bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'], 776 random () % 32768); 777 } 778 if (flag_set['T']) 779 { 780 sprintf (bkpinfo->tmpdir, "%s/tmp.mondo.%ld", flag_val['T'], 781 random () % 32768); 782 sprintf(tmp, "touch %s/.foo.dat", flag_val['T']); 783 if (run_program_and_log_output(tmp, 1)) 784 { 785 retval++; 786 log_to_screen( "Please specify a tempdir which I can write to. :)"); 787 fatal_error("I cannot write to the tempdir you specified."); 788 } 789 sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", flag_val['T'], flag_val['T']); 790 if (run_program_and_log_output(tmp, 1)) 791 { 792 retval++; 793 log_to_screen("Please don't specify a SAMBA or VFAT or NFS tmpdir."); 794 fatal_error("I cannot write to the tempdir you specified."); 795 } 796 } 797 if (flag_set['A']) 798 { 799 strncpy (bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN); 800 } 801 if (flag_set['B']) 802 { 803 strncpy (bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN); 804 } 805 if (flag_set['F']) 806 { 807 g_skip_floppies = TRUE; 808 } 809 if (flag_set['H']) 810 { 811 g_cd_recovery = TRUE; 812 } 813 if (flag_set['l']) 814 { 788 for (i = '0'; i <= '9'; i++) { 789 if (flag_set[i]) { 790 bkpinfo->compression_level = i - '0'; 791 } /* not '\0' but '0' */ 792 } 793 if (flag_set['S']) { 794 sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'], 795 random() % 32768); 796 } 797 if (flag_set['T']) { 798 sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%ld", flag_val['T'], 799 random() % 32768); 800 sprintf(tmp, "touch %s/.foo.dat", flag_val['T']); 801 if (run_program_and_log_output(tmp, 1)) { 802 retval++; 803 log_to_screen 804 ("Please specify a tempdir which I can write to. :)"); 805 fatal_error("I cannot write to the tempdir you specified."); 806 } 807 sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", flag_val['T'], 808 flag_val['T']); 809 if (run_program_and_log_output(tmp, 1)) { 810 retval++; 811 log_to_screen 812 ("Please don't specify a SAMBA or VFAT or NFS tmpdir."); 813 fatal_error("I cannot write to the tempdir you specified."); 814 } 815 } 816 if (flag_set['A']) { 817 strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN); 818 } 819 if (flag_set['B']) { 820 strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN); 821 } 822 if (flag_set['F']) { 823 g_skip_floppies = TRUE; 824 } 825 if (flag_set['H']) { 826 g_cd_recovery = TRUE; 827 } 828 if (flag_set['l']) { 815 829 #ifdef __FreeBSD__ 816 830 # define BOOT_LOADER_CHARS "GLBMR" … … 822 836 # endif 823 837 #endif 824 if (!strchr(BOOT_LOADER_CHARS, (bkpinfo->boot_loader = flag_val['l'][0]))) 825 { 826 log_msg(1, "%c? WTF is %c? I need G, L, E or R.", bkpinfo->boot_loader, bkpinfo->boot_loader); 827 fatal_error("Please specify GRUB, LILO, ELILO or RAW with the -l switch"); 828 } 838 if (!strchr 839 (BOOT_LOADER_CHARS, 840 (bkpinfo->boot_loader = flag_val['l'][0]))) { 841 log_msg(1, "%c? WTF is %c? I need G, L, E or R.", 842 bkpinfo->boot_loader, bkpinfo->boot_loader); 843 fatal_error 844 ("Please specify GRUB, LILO, ELILO or RAW with the -l switch"); 845 } 829 846 #undef BOOT_LOADER_CHARS 830 831 if (flag_set['f']) 832 { 833 strncpy (bkpinfo->boot_device, resolve_softlinks_to_get_to_actual_device_file(flag_val['f']), MAX_STR_LEN/4); 834 } 835 if (flag_set['P']) 836 { 837 strncpy (bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN); 838 } 839 if (flag_set['Q']) 840 841 842 843 844 845 846 if (flag_set['L']) 847 { 848 bkpinfo->use_lzo = TRUE; 849 if (run_program_and_log_output ("which lzop", FALSE)) 850 {851 retval++;852 log_to_screen(853 "Please install LZOP. You can't use '-L' until you do.\n");854 } 855 } 856 857 if (!flag_set['o'] && !run_program_and_log_output("cat /etc/issue.net | grep -i suse | grep 64", TRUE)) 858 859 860 log_to_screen("Forcing you to use LILO. SuSE 9.0 (64-bit) has a broken mkfs.vfat binary."); 861 } 862 if (flag_set['o']) 863 864 865 847 } 848 if (flag_set['f']) { 849 strncpy(bkpinfo->boot_device, 850 resolve_softlinks_to_get_to_actual_device_file(flag_val 851 ['f']), 852 MAX_STR_LEN / 4); 853 } 854 if (flag_set['P']) { 855 strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN); 856 } 857 if (flag_set['Q']) { 858 i = which_boot_loader(tmp); 859 log_msg(3, "boot loader is %c, residing at %s", i, tmp); 860 printf("boot loader is %c, residing at %s\n", i, tmp); 861 finish(0); 862 } 863 if (flag_set['L']) { 864 bkpinfo->use_lzo = TRUE; 865 if (run_program_and_log_output("which lzop", FALSE)) { 866 retval++; 867 log_to_screen 868 ("Please install LZOP. You can't use '-L' until you do.\n"); 869 } 870 } 871 872 if (!flag_set['o'] 873 && 874 !run_program_and_log_output 875 ("cat /etc/issue.net | grep -i suse | grep 64", TRUE)) { 876 bkpinfo->make_cd_use_lilo = TRUE; 877 log_to_screen 878 ("Forcing you to use LILO. SuSE 9.0 (64-bit) has a broken mkfs.vfat binary."); 879 } 880 if (flag_set['o']) { 881 bkpinfo->make_cd_use_lilo = TRUE; 882 } 866 883 #ifndef __FreeBSD__ 867 else 868 { 869 if (!is_this_a_valid_disk_format("vfat")) 870 { 871 bkpinfo->make_cd_use_lilo = TRUE; 872 log_to_screen( "Your kernel appears not to support vfat filesystems. I am therefore"); 873 log_to_screen( "using LILO instead of SYSLINUX as the CD/floppy's boot loader."); 874 } 875 if (run_program_and_log_output("which mkfs.vfat", FALSE)) 876 { 877 bkpinfo->make_cd_use_lilo = TRUE; 884 else { 885 if (!is_this_a_valid_disk_format("vfat")) { 886 bkpinfo->make_cd_use_lilo = TRUE; 887 log_to_screen 888 ("Your kernel appears not to support vfat filesystems. I am therefore"); 889 log_to_screen 890 ("using LILO instead of SYSLINUX as the CD/floppy's boot loader."); 891 } 892 if (run_program_and_log_output("which mkfs.vfat", FALSE)) { 893 bkpinfo->make_cd_use_lilo = TRUE; 878 894 #ifdef __IA32__ 879 log_to_screen( "Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as"); 880 log_to_screen( "your boot loader. I shall therefore use LILO instead."); 895 log_to_screen 896 ("Your filesystem is missing 'mkfs.vfat', so I cannot use SYSLINUX as"); 897 log_to_screen 898 ("your boot loader. I shall therefore use LILO instead."); 881 899 #endif 882 900 #ifdef __IA64__ 883 log_to_screen( "Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI"); 884 log_to_screen( "environment correctly. Please install it."); 885 fatal_error("Aborting"); 901 log_to_screen 902 ("Your filesystem is missing 'mkfs.vfat', so I cannot prepare the EFI"); 903 log_to_screen("environment correctly. Please install it."); 904 fatal_error("Aborting"); 886 905 #endif 887 }906 } 888 907 #ifdef __IA64__ 889 890 908 /* We force ELILO usage on IA64 */ 909 bkpinfo->make_cd_use_lilo = TRUE; 891 910 #endif 892 911 } 893 912 #endif 894 913 895 if (bkpinfo->make_cd_use_lilo && !does_file_exist("/boot/boot.b")) 896 { 897 paranoid_system("touch /boot/boot.b"); 898 } 899 900 i = flag_set['O'] + flag_set['V']; 901 if (i == 0) 902 { 903 retval++; 904 log_to_screen( "Specify backup (-O), verify (-V) or both (-OV).\n"); 905 } 914 if (bkpinfo->make_cd_use_lilo && !does_file_exist("/boot/boot.b")) { 915 paranoid_system("touch /boot/boot.b"); 916 } 917 918 i = flag_set['O'] + flag_set['V']; 919 if (i == 0) { 920 retval++; 921 log_to_screen("Specify backup (-O), verify (-V) or both (-OV).\n"); 922 } 906 923 907 924 /* and finally... */ 908 925 909 910 paranoid_free(psz); 911 926 paranoid_free(tmp); 927 paranoid_free(psz); 928 return (retval); 912 929 } 913 930 … … 926 943 */ 927 944 int 928 retrieve_switches_from_command_line 929 930 945 retrieve_switches_from_command_line(int argc, char *argv[], 946 char flag_val[128][MAX_STR_LEN], 947 bool flag_set[128]) 931 948 { 932 /*@ ints ***/ 933 int opt = 0; 934 char tmp[MAX_STR_LEN]; 935 int i = 0; 936 int len; 937 938 /*@ bools ****/ 939 bool bad_switches = FALSE; 940 941 assert(flag_val!=NULL); 942 assert(flag_set!=NULL); 943 944 for (i = 0; i < 128; i++) 945 { 946 flag_val[i][0] = '\0'; 947 flag_set[i] = FALSE; 948 } 949 while ((opt = 950 getopt (argc, argv, 951 "0123456789A:B:CDE:FHI:J:K:LNOP:QRS:T:VWb:c:d:ef:gik:l:mn:op:rs:tuw:x:")) != 952 -1) 953 { 954 if (opt == '?') 955 { 956 bad_switches = TRUE; 957 /*log_it("Invalid option: %c\n",optopt); */ 958 } 959 else 960 { 961 if (flag_set[optopt]) 962 { 963 bad_switches = TRUE; 964 sprintf(tmp, "Switch -%c previously defined as %s\n", opt, 965 flag_val[i]); 966 log_to_screen(tmp); 967 } 968 else 969 { 970 flag_set[opt] = TRUE; 971 if (optarg) 972 { 973 len = strlen(optarg); 974 if (optarg[0] != '/' && optarg[len-1] == '/') 975 { 976 optarg[--len] = '\0'; 977 log_to_screen("Warning - param '%s' should not have trailing slash!", optarg); 978 } 979 if (opt=='d') 980 { 981 if (strchr(flag_val[opt], '/') && flag_val[opt][0]!='/') 982 { 983 sprintf(tmp, "-%c flag --- must be absolute path --- '%s' isn't absolute", opt, flag_val[opt]); 984 log_to_screen(tmp); 985 bad_switches = TRUE; 986 } 987 } 988 strcpy(flag_val[opt], optarg); 989 } 990 } 991 } 992 } 993 for (i = optind; i < argc; i++) 994 { 995 bad_switches = TRUE; 996 sprintf(tmp, "Invalid arg -- %s\n", argv[i]); 997 log_to_screen(tmp); 998 } 999 return (bad_switches); 949 /*@ ints ** */ 950 int opt = 0; 951 char tmp[MAX_STR_LEN]; 952 int i = 0; 953 int len; 954 955 /*@ bools *** */ 956 bool bad_switches = FALSE; 957 958 assert(flag_val != NULL); 959 assert(flag_set != NULL); 960 961 for (i = 0; i < 128; i++) { 962 flag_val[i][0] = '\0'; 963 flag_set[i] = FALSE; 964 } 965 while ((opt = 966 getopt(argc, argv, 967 "0123456789A:B:CDE:FHI:J:K:LNOP:QRS:T:VWb:c:d:ef:gik:l:mn:op:rs:tuw:x:")) 968 != -1) { 969 if (opt == '?') { 970 bad_switches = TRUE; 971 /*log_it("Invalid option: %c\n",optopt); */ 972 } else { 973 if (flag_set[optopt]) { 974 bad_switches = TRUE; 975 sprintf(tmp, "Switch -%c previously defined as %s\n", opt, 976 flag_val[i]); 977 log_to_screen(tmp); 978 } else { 979 flag_set[opt] = TRUE; 980 if (optarg) { 981 len = strlen(optarg); 982 if (optarg[0] != '/' && optarg[len - 1] == '/') { 983 optarg[--len] = '\0'; 984 log_to_screen 985 ("Warning - param '%s' should not have trailing slash!", 986 optarg); 987 } 988 if (opt == 'd') { 989 if (strchr(flag_val[opt], '/') 990 && flag_val[opt][0] != '/') { 991 sprintf(tmp, 992 "-%c flag --- must be absolute path --- '%s' isn't absolute", 993 opt, flag_val[opt]); 994 log_to_screen(tmp); 995 bad_switches = TRUE; 996 } 997 } 998 strcpy(flag_val[opt], optarg); 999 } 1000 } 1001 } 1002 } 1003 for (i = optind; i < argc; i++) { 1004 bad_switches = TRUE; 1005 sprintf(tmp, "Invalid arg -- %s\n", argv[i]); 1006 log_to_screen(tmp); 1007 } 1008 return (bad_switches); 1000 1009 } 1001 1010 … … 1006 1015 * Print a not-so-helpful help message and exit. 1007 1016 */ 1008 void 1009 help_screen () 1017 void help_screen() 1010 1018 { 1011 log_msg(1,"Type 'man mondo-archive' for more information\n");1012 exit(1);1019 log_msg(1, "Type 'man mondo-archive' for more information\n"); 1020 exit(1); 1013 1021 } 1014 1022 … … 1020 1028 void terminate_daemon(int sig) 1021 1029 { 1022 char tmp[64]; 1023 char tmp2 [MAX_STR_LEN]; 1024 // char command[512]; 1025 // pid_t pid; 1026 1027 switch(sig) 1028 { 1030 char tmp[64]; 1031 char tmp2[MAX_STR_LEN]; 1032 // char command[512]; 1033 // pid_t pid; 1034 1035 switch (sig) { 1029 1036 case SIGINT: 1030 1037 sprintf(tmp, "SIGINT"); … … 1033 1040 case SIGKILL: 1034 1041 sprintf(tmp, "SIGKILL"); 1035 strcpy(tmp2, "I seriously have no clue how this signal even got to me. Something's wrong with your system."); 1042 strcpy(tmp2, 1043 "I seriously have no clue how this signal even got to me. Something's wrong with your system."); 1036 1044 break; 1037 1045 case SIGTERM: 1038 1046 sprintf(tmp, "SIGTERM"); 1039 strcpy 1047 strcpy(tmp2, "Got terminate signal"); 1040 1048 break; 1041 1049 case SIGHUP: 1042 1050 sprintf(tmp, "SIGHUP"); 1043 strcpy 1051 strcpy(tmp2, "Hangup on line"); 1044 1052 break; 1045 1053 case SIGSEGV: 1046 1054 sprintf(tmp, "SIGSEGV"); 1047 strcpy (tmp2, "Internal programming error. Please send a backtrace as well as your log."); 1055 strcpy(tmp2, 1056 "Internal programming error. Please send a backtrace as well as your log."); 1048 1057 break; 1049 1058 case SIGPIPE: 1050 1059 sprintf(tmp, "SIGPIPE"); 1051 strcpy 1060 strcpy(tmp2, "Pipe was broken"); 1052 1061 break; 1053 case SIGABRT: 1054 sprintf (tmp, "SIGABRT"); 1055 sprintf (tmp2, "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message."); 1056 break; 1062 case SIGABRT: 1063 sprintf(tmp, "SIGABRT"); 1064 sprintf(tmp2, 1065 "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message."); 1066 break; 1057 1067 default: 1058 1068 sprintf(tmp, "(Unknown)"); 1059 } 1060 1061 strcat(tmp, " signal received from OS"); 1062 log_to_screen(tmp); 1063 log_to_screen (tmp2); 1064 if (sig == SIGABRT) { 1065 sleep (10); 1066 } 1067 kill_buffer(); 1068 fatal_error("Mondoarchive is terminating in response to a signal from the OS"); 1069 finish(254); // just in case 1069 } 1070 1071 strcat(tmp, " signal received from OS"); 1072 log_to_screen(tmp); 1073 log_to_screen(tmp2); 1074 if (sig == SIGABRT) { 1075 sleep(10); 1076 } 1077 kill_buffer(); 1078 fatal_error 1079 ("Mondoarchive is terminating in response to a signal from the OS"); 1080 finish(254); // just in case 1070 1081 } 1071 1082 … … 1079 1090 void set_signals(int on) 1080 1091 { 1081 int signals[]= { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 }; 1082 int i; 1083 1084 signal(SIGPIPE, sigpipe_occurred); 1085 for (i=0; signals[i]; i++) 1086 { 1087 if (on) 1088 { signal(signals[i], terminate_daemon); } 1089 else 1090 { signal(signals[i], termination_in_progress); } 1091 } 1092 int signals[] = 1093 { SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGKILL, SIGSTOP, 0 }; 1094 int i; 1095 1096 signal(SIGPIPE, sigpipe_occurred); 1097 for (i = 0; signals[i]; i++) { 1098 if (on) { 1099 signal(signals[i], terminate_daemon); 1100 } else { 1101 signal(signals[i], termination_in_progress); 1102 } 1103 } 1092 1104 } 1093 1105 … … 1101 1113 void termination_in_progress(int sig) 1102 1114 { 1103 1104 1105 1115 log_msg(1, "Termination in progress"); 1116 usleep(1000); 1117 pthread_exit(0); 1106 1118 } 1107 1119 -
trunk/mondo/mondo/mondoarchive/mondo-cli.h
r30 r59 1 1 /* mondo-cli.h 2 * $Id : mondo-cli.h,v 1.2 2004/06/10 15:29:13 hugo Exp$2 * $Id$ 3 3 */ 4 4 5 int handle_incoming_parameters (int argc, char *argv[], struct s_bkpinfo *bkpinfo); 5 int handle_incoming_parameters(int argc, char *argv[], 6 struct s_bkpinfo *bkpinfo); 6 7 int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value); 7 int process_switches (struct s_bkpinfo *bkpinfo, char flag_val[128][MAX_STR_LEN],8 9 int retrieve_switches_from_command_line 10 11 12 void help_screen 8 int process_switches(struct s_bkpinfo *bkpinfo, 9 char flag_val[128][MAX_STR_LEN], bool flag_set[128]); 10 int retrieve_switches_from_command_line(int argc, char *argv[], 11 char flag_val[128][MAX_STR_LEN], 12 bool flag_set[128]); 13 void help_screen(); 13 14 void terminate_daemon(int sig); 14 15 void set_signals(int on); 15 16 void termination_in_progress(int sig); 16 17 -
trunk/mondo/mondo/mondorestore/mondo-prep.c
r30 r59 8 8 edited by : by Stan Benoit 4/2002 9 9 email : troff@nakedsoul.org 10 cvsid : $Id : mondo-prep.c,v 1.14 2004/06/21 20:20:36 hugo Exp$10 cvsid : $Id$ 11 11 ***************************************************************************/ 12 12 … … 181 181 #define MONDO_WAS_HERE "MONDOWOZEREMONDOWOZEREMONDOWOZEREhahahaMOJOJOJO" 182 182 183 //static char cvsid[] = "$Id : mondo-prep.c,v 1.14 2004/06/21 20:20:36 hugo Exp$";183 //static char cvsid[] = "$Id$"; 184 184 185 185 extern char *g_mountlist_fname; … … 188 188 extern bool g_text_mode; 189 189 190 extern void pause_for_N_seconds(int, char *);191 192 193 FILE *g_fprep =NULL;194 195 196 197 int g_partition_table_locked_up =0;190 extern void pause_for_N_seconds(int, char *); 191 192 193 FILE *g_fprep = NULL; 194 195 196 197 int g_partition_table_locked_up = 0; 198 198 199 199 … … 208 208 void wipe_MBRs_and_reboot_if_necessary(struct mountlist_itself *mountlist) 209 209 { 210 211 212 213 214 FILE*fout;215 216 const int blocksize=512; 217 struct list_of_disks *drivelist=NULL;210 char *command; 211 char *tmp; 212 int lino; 213 int i; 214 FILE *fout; 215 char *buf; 216 const int blocksize = 512; 217 struct list_of_disks *drivelist = NULL; 218 218 // If LVMs are present and a zero-and-reboot wasn't recently undertaken 219 219 // then zero & insist on reboot. 220 221 222 223 if (does_file_exist("/tmp/i-want-my-lvm"))// FIXME - cheating :)224 225 226 227 for (lino = 0; lino < drivelist->entries; lino++)228 {229 sprintf(command, "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"", drivelist->el[lino].device, MONDO_WAS_HERE);230 if (!run_program_and_log_output(command, 1))231 232 log_msg(1, "Found MONDO_WAS_HERE marker on drive#%d (%s)", lino, drivelist->el[lino].device);233 break;234 }235 236 237 if (lino==drivelist->entries) 238 220 malloc_string(command); 221 malloc_string(tmp); 222 buf = malloc(blocksize); 223 if (does_file_exist("/tmp/i-want-my-lvm")) // FIXME - cheating :) 224 { 225 drivelist = malloc(sizeof(struct list_of_disks)); 226 make_list_of_drives_in_mountlist(mountlist, drivelist); 227 for (lino = 0; lino < drivelist->entries; lino++) { 228 sprintf(command, 229 "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"", 230 drivelist->el[lino].device, MONDO_WAS_HERE); 231 if (!run_program_and_log_output(command, 1)) { 232 log_msg(1, "Found MONDO_WAS_HERE marker on drive#%d (%s)", 233 lino, drivelist->el[lino].device); 234 break; 235 } 236 } 237 238 if (lino == drivelist->entries) { 239 239 // zero & reboot 240 log_to_screen("I am sorry for the inconvenience but I must ask you to reboot."); 241 log_to_screen("I need to reset the Master Boot Record; in order to be"); 242 log_to_screen("sure the kernel notices, I must reboot after doing it."); 243 log_to_screen("Please hit 'Enter' to reboot."); 244 for (lino = 0; lino < drivelist->entries; lino++) 245 { 246 for(i=0;i<blocksize; i++) 247 { buf[i] = 0; } 248 sprintf(buf, "%s\n", MONDO_WAS_HERE); 249 fout = fopen(drivelist->el[lino].device, "w+"); 250 if (!fout) 251 { 252 log_msg(1, "Unable to open+wipe %s", drivelist->el[lino].device); 253 } 254 else 255 { 256 if (1!=fwrite(buf, blocksize, 1, fout)) 257 { 258 log_msg(1, "Failed to wipe %s", drivelist->el[lino].device); 259 } 260 else 261 { 262 log_msg(1, "Successfully wiped %s", drivelist->el[lino].device); 263 } 264 fclose(fout); 265 } 266 } 267 system("sync"); system("sync"); system("sync"); 268 popup_and_OK("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine."); 269 system("reboot"); 270 } 271 } 272 240 log_to_screen 241 ("I am sorry for the inconvenience but I must ask you to reboot."); 242 log_to_screen 243 ("I need to reset the Master Boot Record; in order to be"); 244 log_to_screen 245 ("sure the kernel notices, I must reboot after doing it."); 246 log_to_screen("Please hit 'Enter' to reboot."); 247 for (lino = 0; lino < drivelist->entries; lino++) { 248 for (i = 0; i < blocksize; i++) { 249 buf[i] = 0; 250 } 251 sprintf(buf, "%s\n", MONDO_WAS_HERE); 252 fout = fopen(drivelist->el[lino].device, "w+"); 253 if (!fout) { 254 log_msg(1, "Unable to open+wipe %s", 255 drivelist->el[lino].device); 256 } else { 257 if (1 != fwrite(buf, blocksize, 1, fout)) { 258 log_msg(1, "Failed to wipe %s", 259 drivelist->el[lino].device); 260 } else { 261 log_msg(1, "Successfully wiped %s", 262 drivelist->el[lino].device); 263 } 264 fclose(fout); 265 } 266 } 267 system("sync"); 268 system("sync"); 269 system("sync"); 270 popup_and_OK 271 ("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine."); 272 system("reboot"); 273 } 274 } 273 275 // Still here? Cool! 274 275 276 276 paranoid_free(command); 277 paranoid_free(tmp); 278 log_msg(1, "Cool. I didn't have to wipe anything."); 277 279 } 278 280 … … 282 284 283 285 284 int fput_string_one_char_at_a_time(FILE *fout, char*str)286 int fput_string_one_char_at_a_time(FILE * fout, char *str) 285 287 { 286 int i, j; 287 FILE*fq; 288 289 if (ferror(fout)) 290 { 291 return(-1); 292 } 293 log_msg(5, "Writing string '%s', one char at a time", str); 294 j = strlen(str); 295 for(i=0; i<j; i++) 296 { 297 log_msg(6, "Writing %d ('%c')", str[i], str[i]); 298 if ((fq = fopen(FDISK_LOG, "a+"))) { fputc(str[i], fq);fclose(fq); } 299 fputc(str[i], fout); 300 fflush(fout); 301 usleep(1000L*100L); 302 if (str[i]<32) { usleep(1000L*10L); } 303 } 304 log_msg(5, "Returning"); 305 306 return(i); 288 int i, j; 289 FILE *fq; 290 291 if (ferror(fout)) { 292 return (-1); 293 } 294 log_msg(5, "Writing string '%s', one char at a time", str); 295 j = strlen(str); 296 for (i = 0; i < j; i++) { 297 log_msg(6, "Writing %d ('%c')", str[i], str[i]); 298 if ((fq = fopen(FDISK_LOG, "a+"))) { 299 fputc(str[i], fq); 300 fclose(fq); 301 } 302 fputc(str[i], fout); 303 fflush(fout); 304 usleep(1000L * 100L); 305 if (str[i] < 32) { 306 usleep(1000L * 10L); 307 } 308 } 309 log_msg(5, "Returning"); 310 311 return (i); 307 312 } 308 313 … … 325 330 * @return The number of errors encountered (0 for success). 326 331 */ 327 328 329 int do_my_funky_lvm_stuff(bool just_erase_existing_volumes, bool vacuum_pack) 332 333 334 int do_my_funky_lvm_stuff(bool just_erase_existing_volumes, 335 bool vacuum_pack) 330 336 { 331 337 /** buffers **********************************************/ … … 340 346 char *vgchange_sz; 341 347 char *vgremove_sz; 342 // 348 // char *do_this_last; 343 349 344 350 /** char **************************************************/ … … 353 359 long extents; 354 360 fpos_t orig_pos; 355 361 356 362 /** pointers **********************************************/ 357 363 FILE *fin; … … 377 383 malloc_string(vgchange_sz); 378 384 malloc_string(vgremove_sz); 379 // 385 // malloc_string(do_this_last); // postpone lvcreate call if necessary 380 386 command = malloc(512); 381 387 382 // 383 iamhere("STARTING");388 // do_this_last[0] = '\0'; 389 iamhere("STARTING"); 384 390 log_msg(1, "OK, opened i-want-my-lvm. Shutting down LVM volumes..."); 385 if (find_home_of_exe("lvm")) // found it :) cool 386 { 387 strcpy(lvscan_sz, "lvm lvscan"); 388 strcpy(lvremove_sz, "lvm lvremove"); 389 strcpy(vgscan_sz, "lvm vgscan"); 390 strcpy(pvscan_sz, "lvm pvscan"); 391 strcpy(vgcreate_sz, "lvm vgcreate"); 392 strcpy(vgchange_sz, "lvm vgchange"); 393 strcpy(vgremove_sz, "lvm vgremove"); 394 } 395 else 396 { 397 strcpy(lvscan_sz, "lvscan"); 398 strcpy(lvremove_sz, "lvremove"); 399 strcpy(vgscan_sz, "vgscan"); 400 strcpy(pvscan_sz, "pvscan"); 401 strcpy(vgcreate_sz, "vgcreate"); 402 strcpy(vgchange_sz, "vgchange"); 403 strcpy(vgremove_sz, "vgremove"); 404 } 405 sprintf(command, "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> " MONDO_LOGFILE "; %s -f $i; done", 406 lvscan_sz, lvremove_sz); 391 if (find_home_of_exe("lvm")) // found it :) cool 392 { 393 strcpy(lvscan_sz, "lvm lvscan"); 394 strcpy(lvremove_sz, "lvm lvremove"); 395 strcpy(vgscan_sz, "lvm vgscan"); 396 strcpy(pvscan_sz, "lvm pvscan"); 397 strcpy(vgcreate_sz, "lvm vgcreate"); 398 strcpy(vgchange_sz, "lvm vgchange"); 399 strcpy(vgremove_sz, "lvm vgremove"); 400 } else { 401 strcpy(lvscan_sz, "lvscan"); 402 strcpy(lvremove_sz, "lvremove"); 403 strcpy(vgscan_sz, "vgscan"); 404 strcpy(pvscan_sz, "pvscan"); 405 strcpy(vgcreate_sz, "vgcreate"); 406 strcpy(vgchange_sz, "vgchange"); 407 strcpy(vgremove_sz, "vgremove"); 408 } 409 sprintf(command, 410 "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> " 411 MONDO_LOGFILE "; %s -f $i; done", lvscan_sz, lvremove_sz); 407 412 run_program_and_log_output(command, 5); 408 413 sleep(1); 409 sprintf(command, "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> " MONDO_LOGFILE "; done; %s -a n", vgscan_sz, vgchange_sz, vgremove_sz, vgremove_sz); 414 sprintf(command, 415 "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> " 416 MONDO_LOGFILE "; done; %s -a n", vgscan_sz, vgchange_sz, 417 vgremove_sz, vgremove_sz); 410 418 run_program_and_log_output(command, 5); 411 419 if (just_erase_existing_volumes) { 412 420 paranoid_fclose(fin); 413 421 log_msg(1, "Closed i-want-my-lvm. Finished erasing LVMs."); 414 retval =0;422 retval = 0; 415 423 goto end_of_i_want_my_lvm; 416 424 } … … 423 431 continue; 424 432 } 425 if (res && strstr(command, "create") && vacuum_pack) 426 {427 sleep(2);428 system("sync"); system("sync");system("sync");429 }430 if ((p=strstr(incoming, "vgcreate")))431 433 if (res && strstr(command, "create") && vacuum_pack) { 434 sleep(2); 435 system("sync"); 436 system("sync"); 437 system("sync"); 438 } 439 if ((p = strstr(incoming, "vgcreate"))) { 432 440 // include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm) 433 for (fgets(tmp, 512, fin); !feof(fin); fgets(tmp, 512, fin)) { 434 if (tmp[0] == '#') { 435 fsetpos(fin, &orig_pos); 436 break; 437 } else { 438 fgetpos(fin, &orig_pos); 439 strcat(incoming, tmp); 440 } 441 } 442 for(q=incoming; *q!='\0'; q++) 443 { 444 if (*q<32) { *q=' '; } 445 } 446 strcpy(tmp, p+strlen("vgcreate")+1); 447 for(q=tmp; *q>32; q++); 448 *q = '\0'; 449 log_msg(1, "Deleting old entries at /dev/%s", tmp); 450 // sprintf(command, "%s -f %s", vgremove_sz, tmp); 451 // run_program_and_log_output(command, 1); 452 sprintf(command, "rm -Rf /dev/%s", tmp); 453 run_program_and_log_output(command, 1); 454 run_program_and_log_output(vgscan_sz, 1); 455 run_program_and_log_output(pvscan_sz, 1); 456 log_msg(3, "After working around potentially broken i-want-my-lvm, incoming[] is now '%s'", incoming); 457 } 441 for (fgets(tmp, 512, fin); !feof(fin); fgets(tmp, 512, fin)) { 442 if (tmp[0] == '#') { 443 fsetpos(fin, &orig_pos); 444 break; 445 } else { 446 fgetpos(fin, &orig_pos); 447 strcat(incoming, tmp); 448 } 449 } 450 for (q = incoming; *q != '\0'; q++) { 451 if (*q < 32) { 452 *q = ' '; 453 } 454 } 455 strcpy(tmp, p + strlen("vgcreate") + 1); 456 for (q = tmp; *q > 32; q++); 457 *q = '\0'; 458 log_msg(1, "Deleting old entries at /dev/%s", tmp); 459 // sprintf(command, "%s -f %s", vgremove_sz, tmp); 460 // run_program_and_log_output(command, 1); 461 sprintf(command, "rm -Rf /dev/%s", tmp); 462 run_program_and_log_output(command, 1); 463 run_program_and_log_output(vgscan_sz, 1); 464 run_program_and_log_output(pvscan_sz, 1); 465 log_msg(3, 466 "After working around potentially broken i-want-my-lvm, incoming[] is now '%s'", 467 incoming); 468 } 458 469 for (p = incoming + 1; *p == ' '; p++); 459 470 strcpy(command, p); … … 462 473 *p = '\0'; 463 474 res = run_program_and_log_output(command, 5); 464 if (res>0 && (p=strstr(command, "lvm "))) 465 { 466 *p = *(p+1) = *(p+2) = ' '; 467 res = run_program_and_log_output(command, 5); 468 } 475 if (res > 0 && (p = strstr(command, "lvm "))) { 476 *p = *(p + 1) = *(p + 2) = ' '; 477 res = run_program_and_log_output(command, 5); 478 } 469 479 log_msg(0, "%s --> %d", command, res); 470 if (res>0) {res=1;} 471 if (res && strstr(command, "lvcreate") && vacuum_pack) 472 { 473 res=0; 474 if (strstr(command, "lvm lvcreate")) 475 lvmversion = 2; 476 log_it("%s... so I'll get creative.", tmp); 477 if (lvmversion == 2) 478 { 479 strcpy(tmp, call_program_and_get_last_line_of_output 480 ("cat /var/log/mondo-archive.log | tail -n5 | grep Insufficient | tail -n1")); 481 } 482 else 483 { 484 strcpy(tmp, call_program_and_get_last_line_of_output 485 ("cat /var/log/mondo-archive.log | tail -n5 | grep lvcreate | tail -n1")); 486 } 487 for(p=tmp; *p!='\0' && !isdigit(*p); p++); 488 extents = atol(p); 489 log_msg(5, "p='%s' --> extents=%ld", p, extents); 490 p = strstr(command, "-L"); 491 if (!p) 492 { 493 log_msg(0, "Fiddlesticks. '%s' returned %d", command, res); 494 } 495 else 496 { 497 if (lvmversion == 2) 498 { 499 *p++ = '-'; *p++ = 'l'; *p++ = ' '; 500 for(q=p; *q!=' '; q++) { *q = ' '; } 501 sprintf(p, "%ld", extents); 502 i = strlen(p); 503 *(p+i) = ' '; 504 } 505 else 506 { 507 p++; p++; p++; 508 for(q=p; *q!=' '; q++) { *(q-1) = ' '; } 509 sprintf(p, "%ld%c", extents, 'm'); 510 i = strlen(p); 511 *(p+i) = ' '; 512 } 513 log_msg(5, "Retrying with '%s'", command); 514 res = run_program_and_log_output(command, 5); 515 if (res>0) { res=1; } 516 if (g_fprep) { fprintf(g_fprep, "%s\n", command); } 517 log_msg(0, "%s --> %d", command, res); 518 if (!res) 519 { 520 log_msg(5, "YAY! This time, it succeeded."); 521 } 522 } 523 } 524 if (strstr(command, "vgcreate")) 525 { 526 log_msg(0, "In case you're interested..."); 527 run_program_and_log_output(vgscan_sz, 1); 528 run_program_and_log_output(pvscan_sz, 1); 529 } 530 if (res!=0 && !strstr(command, "insmod")) { 531 retval ++; 480 if (res > 0) { 481 res = 1; 482 } 483 if (res && strstr(command, "lvcreate") && vacuum_pack) { 484 res = 0; 485 if (strstr(command, "lvm lvcreate")) 486 lvmversion = 2; 487 log_it("%s... so I'll get creative.", tmp); 488 if (lvmversion == 2) { 489 strcpy(tmp, call_program_and_get_last_line_of_output 490 ("cat /var/log/mondo-archive.log | tail -n5 | grep Insufficient | tail -n1")); 491 } else { 492 strcpy(tmp, call_program_and_get_last_line_of_output 493 ("cat /var/log/mondo-archive.log | tail -n5 | grep lvcreate | tail -n1")); 494 } 495 for (p = tmp; *p != '\0' && !isdigit(*p); p++); 496 extents = atol(p); 497 log_msg(5, "p='%s' --> extents=%ld", p, extents); 498 p = strstr(command, "-L"); 499 if (!p) { 500 log_msg(0, "Fiddlesticks. '%s' returned %d", command, res); 501 } else { 502 if (lvmversion == 2) { 503 *p++ = '-'; 504 *p++ = 'l'; 505 *p++ = ' '; 506 for (q = p; *q != ' '; q++) { 507 *q = ' '; 508 } 509 sprintf(p, "%ld", extents); 510 i = strlen(p); 511 *(p + i) = ' '; 512 } else { 513 p++; 514 p++; 515 p++; 516 for (q = p; *q != ' '; q++) { 517 *(q - 1) = ' '; 518 } 519 sprintf(p, "%ld%c", extents, 'm'); 520 i = strlen(p); 521 *(p + i) = ' '; 522 } 523 log_msg(5, "Retrying with '%s'", command); 524 res = run_program_and_log_output(command, 5); 525 if (res > 0) { 526 res = 1; 527 } 528 if (g_fprep) { 529 fprintf(g_fprep, "%s\n", command); 530 } 531 log_msg(0, "%s --> %d", command, res); 532 if (!res) { 533 log_msg(5, "YAY! This time, it succeeded."); 534 } 535 } 536 } 537 if (strstr(command, "vgcreate")) { 538 log_msg(0, "In case you're interested..."); 539 run_program_and_log_output(vgscan_sz, 1); 540 run_program_and_log_output(pvscan_sz, 1); 541 } 542 if (res != 0 && !strstr(command, "insmod")) { 543 retval++; 532 544 } 533 545 sprintf(tmp, "echo \"%s\" >> /tmp/out.sh", command); … … 537 549 paranoid_fclose(fin); 538 550 log_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff."); 539 end_of_i_want_my_lvm:551 end_of_i_want_my_lvm: 540 552 paranoid_free(tmp); 541 553 paranoid_free(incoming); … … 548 560 paranoid_free(vgchange_sz); 549 561 paranoid_free(vgremove_sz); 550 // paranoid_free(do_this_last); 551 system("sync"); system("sync"); system("sync"); 562 // paranoid_free(do_this_last); 563 system("sync"); 564 system("sync"); 565 system("sync"); 552 566 sleep(1); 553 iamhere("ENDING"); 554 if (retval>2) 555 { 556 log_msg(1, "%d errors. I'm reporting this.", retval); 557 return(retval); 558 } 559 else 560 { 561 log_msg(1, "Not many errors. Returning 0."); 562 return(0); 563 } 567 iamhere("ENDING"); 568 if (retval > 2) { 569 log_msg(1, "%d errors. I'm reporting this.", retval); 570 return (retval); 571 } else { 572 log_msg(1, "Not many errors. Returning 0."); 573 return (0); 574 } 564 575 } 565 576 … … 574 585 * @return 0 for success, nonzero for failure. 575 586 */ 576 577 578 587 int extrapolate_mountlist_to_include_raid_partitions(struct mountlist_itself 588 *new_mountlist, struct mountlist_itself 589 *old_mountlist) 579 590 { 580 591 /** pointers *********************************************************/ … … 603 614 604 615 #ifdef __FreeBSD__ 605 log_to_screen ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry."); 606 return(1); 616 log_to_screen 617 ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry."); 618 return (1); 607 619 #endif 608 620 … … 611 623 { 612 624 if (!does_file_exist("/etc/raidtab")) { 613 log_to_screen("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries"); 625 log_to_screen 626 ("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries"); 614 627 finish(1); 615 628 } … … 619 632 } 620 633 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) 621 && !strstr(incoming, old_mountlist->el[lino].device); fgets(incoming, MAX_STR_LEN - 1, fin)); 634 && !strstr(incoming, old_mountlist->el[lino].device); 635 fgets(incoming, MAX_STR_LEN - 1, fin)); 622 636 if (!feof(fin)) { 623 sprintf(tmp, "Investigating %s", old_mountlist->el[lino].device); 637 sprintf(tmp, "Investigating %s", 638 old_mountlist->el[lino].device); 624 639 log_it(tmp); 625 640 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) 626 && !strstr(incoming, "raiddev"); fgets(incoming, MAX_STR_LEN - 1, fin)) { 641 && !strstr(incoming, "raiddev"); 642 fgets(incoming, MAX_STR_LEN - 1, fin)) { 627 643 if (strstr(incoming, OSSWAP("device", "drive")) 628 && !strchr(incoming, '#')) { 629 for (p = incoming + strlen(incoming); *(p - 1) <= 32; p--); 644 && !strchr(incoming, '#')) { 645 for (p = incoming + strlen(incoming); 646 *(p - 1) <= 32; p--); 630 647 *p = '\0'; 631 648 for (p--; p > incoming && *(p - 1) > 32; p--); 632 649 sprintf(tmp, "Extrapolating %s", p); 633 650 log_it(tmp); 634 for (j = 0; j < new_mountlist->entries && strcmp(new_mountlist->el[j].device, p); 635 j++); 651 for (j = 0; 652 j < new_mountlist->entries 653 && strcmp(new_mountlist->el[j].device, p); 654 j++); 636 655 if (j >= new_mountlist->entries) { 637 strcpy(new_mountlist->el[new_mountlist->entries].device, p); 638 strcpy(new_mountlist->el[new_mountlist->entries].mountpoint, "raid"); 639 strcpy(new_mountlist->el[new_mountlist->entries].format, "raid"); 640 new_mountlist->el[new_mountlist->entries].size = 641 old_mountlist->el[lino].size; 656 strcpy(new_mountlist-> 657 el[new_mountlist->entries].device, p); 658 strcpy(new_mountlist-> 659 el[new_mountlist->entries].mountpoint, 660 "raid"); 661 strcpy(new_mountlist-> 662 el[new_mountlist->entries].format, 663 "raid"); 664 new_mountlist->el[new_mountlist->entries]. 665 size = old_mountlist->el[lino].size; 642 666 new_mountlist->entries++; 643 667 } else { 644 sprintf(tmp, "Not adding %s to mountlist: it's already there", p); 668 sprintf(tmp, 669 "Not adding %s to mountlist: it's already there", 670 p); 645 671 log_it(tmp); 646 672 } … … 650 676 paranoid_fclose(fin); 651 677 } else { 652 strcpy(new_mountlist->el[new_mountlist->entries].device, old_mountlist->el[lino].device); 653 strcpy(new_mountlist->el[new_mountlist->entries].mountpoint, old_mountlist->el[lino].mountpoint); 654 strcpy(new_mountlist->el[new_mountlist->entries].format, old_mountlist->el[lino].format); 655 new_mountlist->el[new_mountlist->entries].size = old_mountlist->el[lino].size; 678 strcpy(new_mountlist->el[new_mountlist->entries].device, 679 old_mountlist->el[lino].device); 680 strcpy(new_mountlist->el[new_mountlist->entries].mountpoint, 681 old_mountlist->el[lino].mountpoint); 682 strcpy(new_mountlist->el[new_mountlist->entries].format, 683 old_mountlist->el[lino].format); 684 new_mountlist->el[new_mountlist->entries].size = 685 old_mountlist->el[lino].size; 656 686 new_mountlist->entries++; 657 687 } … … 697 727 sprintf(tmp, "Not formatting %s (it is a RAID disk)", device); 698 728 log_it(tmp); 699 paranoid_free(program); paranoid_free(tmp); 729 paranoid_free(program); 730 paranoid_free(tmp); 700 731 return (0); 701 732 } … … 703 734 if (strcmp(format, "swap") == 0) { 704 735 log_it("Not formatting %s - it's swap", device); 705 paranoid_free(program); paranoid_free(tmp); 736 paranoid_free(program); 737 paranoid_free(tmp); 706 738 return (0); 707 739 } … … 709 741 if (strlen(format) <= 2) { 710 742 sprintf(tmp, 711 "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it",712 device, format);743 "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it", 744 device, format); 713 745 log_it(tmp); 714 paranoid_free(program); paranoid_free(tmp); 746 paranoid_free(program); 747 paranoid_free(tmp); 715 748 return (0); 716 749 } … … 718 751 sprintf(tmp, "%s is mounted - cannot format it ", device); 719 752 log_to_screen(tmp); 720 paranoid_free(program); paranoid_free(tmp); 753 paranoid_free(program); 754 paranoid_free(tmp); 721 755 return (1); 722 756 } … … 726 760 if (!vinum_started_yet) { 727 761 if (!does_file_exist("/tmp/raidconf.txt")) { 728 log_to_screen("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum."); 762 log_to_screen 763 ("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum."); 729 764 } else { 730 765 int res; 731 res = run_program_and_log_output("vinum create /tmp/raidconf.txt", TRUE); 766 res = 767 run_program_and_log_output 768 ("vinum create /tmp/raidconf.txt", TRUE); 732 769 if (res) { 733 770 log_to_screen 734 771 ("`vinum create /tmp/raidconf.txt' returned errors. Please fix them and re-run mondorestore."); 735 772 finish(1); 736 773 } … … 742 779 FILE *fin; 743 780 char line[MAX_STR_LEN]; 744 sprintf(tmp, "Initializing Vinum device %s (this may take a *long* time)", device); 781 sprintf(tmp, 782 "Initializing Vinum device %s (this may take a *long* time)", 783 device); 745 784 log_to_screen(tmp); 746 785 /* format raid partition */ 747 786 // sprintf (program, "mkraid --really-force %s", device); --- disabled -- BB, 02/12/2003 748 787 sprintf(program, 749 "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes",750 basename(device));788 "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes", 789 basename(device)); 751 790 system(program); 752 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 791 if (g_fprep) { 792 fprintf(g_fprep, "%s\n", program); 793 } 753 794 fin = fopen("/tmp/plexes", "r"); 754 795 while (fgets(line, MAX_STR_LEN - 1, fin)) { … … 762 803 while (1) { 763 804 sprintf(tmp, 764 "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'",765 line);805 "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'", 806 line); 766 807 FILE *pin = popen(tmp, "r"); 767 808 char status[MAX_STR_LEN / 4]; … … 788 829 log_to_screen("Stopping %s", device); 789 830 stop_raid_device(device); 790 system("sync"); sleep(1); 791 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 831 system("sync"); 832 sleep(1); 833 if (g_fprep) { 834 fprintf(g_fprep, "%s\n", program); 835 } 792 836 793 837 log_msg(1, "Making %s", device); … … 795 839 res = run_program_and_log_output(program, 1); 796 840 log_msg(1, "%s returned %d", program, res); 797 system("sync"); sleep(3); 841 system("sync"); 842 sleep(3); 798 843 start_raid_device(device); 799 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 800 system("sync"); sleep(2); 801 802 // log_to_screen("Starting %s", device); 803 // sprintf(program, "raidstart %s", device); 804 // res = run_program_and_log_output(program, 1); 805 // log_msg(1, "%s returned %d", program, res); 806 // system("sync"); sleep(1); 807 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 808 809 #endif 810 system("sync"); sleep(1); 844 if (g_fprep) { 845 fprintf(g_fprep, "%s\n", program); 846 } 847 system("sync"); 848 sleep(2); 849 850 // log_to_screen("Starting %s", device); 851 // sprintf(program, "raidstart %s", device); 852 // res = run_program_and_log_output(program, 1); 853 // log_msg(1, "%s returned %d", program, res); 854 // system("sync"); sleep(1); 855 if (g_fprep) { 856 fprintf(g_fprep, "%s\n", program); 857 } 858 #endif 859 system("sync"); 860 sleep(1); 811 861 newtResume(); 812 862 } … … 814 864 //#endif 815 865 816 if (!strcmp(format, "lvm")) 817 {818 log_msg(1, "Don't format %s - it's part of an lvm volume", device);819 paranoid_free(program);paranoid_free(tmp);820 return(0);821 866 if (!strcmp(format, "lvm")) { 867 log_msg(1, "Don't format %s - it's part of an lvm volume", device); 868 paranoid_free(program); 869 paranoid_free(tmp); 870 return (0); 871 } 822 872 res = which_format_command_do_i_need(format, program); 823 873 sprintf(tmp, "%s %s", program, device); … … 830 880 res = run_program_and_log_output(program, FALSE); 831 881 if (res && strstr(program, "kludge")) { 832 sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s", format, device); 882 sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s", 883 format, device); 833 884 #ifdef __FreeBSD__ 834 885 sprintf(program, "newfs_msdos -F 32 %s", device); … … 837 888 #endif 838 889 res = run_program_and_log_output(program, FALSE); 839 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 890 if (g_fprep) { 891 fprintf(g_fprep, "%s\n", program); 892 } 840 893 } 841 894 retval += res; … … 847 900 848 901 log_to_screen(tmp); 849 paranoid_free(program); paranoid_free(tmp); 850 system("sync"); sleep(1); 902 paranoid_free(program); 903 paranoid_free(tmp); 904 system("sync"); 905 sleep(1); 851 906 return (retval); 852 907 } … … 862 917 * @return The number of errors encountered (0 for success). 863 918 */ 864 int format_everything(struct mountlist_itself *mountlist, bool interactively) 919 int format_everything(struct mountlist_itself *mountlist, 920 bool interactively) 865 921 { 866 922 /** int **************************************************************/ … … 868 924 int lino; 869 925 int res; 870 // 871 // 926 // int i; 927 // struct list_of_disks *drivelist; 872 928 873 929 /** long *************************************************************/ … … 884 940 /** end **************************************************************/ 885 941 886 assert(mountlist !=NULL);942 assert(mountlist != NULL); 887 943 malloc_string(tmp); 888 sprintf(tmp, "format_everything (mountlist, interactively = %s", (interactively) ? "true" : "false"); 944 sprintf(tmp, "format_everything (mountlist, interactively = %s", 945 (interactively) ? "true" : "false"); 889 946 log_it(tmp); 890 947 mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions "); 891 open_progress_form("Formatting partitions", "I am now formatting your hard disk partitions.", 892 "This may take up to five minutes.", "", mountlist->entries + 1); 893 894 progress_step = (mountlist->entries > 0) ? g_maximum_progress / mountlist->entries : 1; 948 open_progress_form("Formatting partitions", 949 "I am now formatting your hard disk partitions.", 950 "This may take up to five minutes.", "", 951 mountlist->entries + 1); 952 953 progress_step = 954 (mountlist->entries > 955 0) ? g_maximum_progress / mountlist->entries : 1; 895 956 // start soft-raids now (because LVM might depend on them) 896 957 // ...and for simplicity's sake, let's format them at the same time :) 897 958 log_msg(1, "Stopping all RAID devices"); 898 959 stop_all_raid_devices(mountlist); 899 system("sync"); system("sync"); system("sync"); 960 system("sync"); 961 system("sync"); 962 system("sync"); 900 963 sleep(2); 901 log_msg(1, "Prepare soft-RAIDs"); 964 log_msg(1, "Prepare soft-RAIDs"); // prep and format too 902 965 for (lino = 0; lino < mountlist->entries; lino++) { 903 966 me = &mountlist->el[lino]; // the current mountlist entry … … 906 969 if (interactively) { 907 970 // ask user if we should format the current device 908 sprintf(tmp, "Shall I format %s (%s) ?", me->device, me->mountpoint); 971 sprintf(tmp, "Shall I format %s (%s) ?", me->device, 972 me->mountpoint); 909 973 do_it = ask_me_yes_or_no(tmp); 910 974 } else { … … 912 976 } 913 977 if (do_it) { 914 // NB: format_device() also stops/starts RAID device if necessary978 // NB: format_device() also stops/starts RAID device if necessary 915 979 retval += format_device(me->device, me->format); 916 980 } … … 918 982 } 919 983 } 920 system("sync"); system("sync"); system("sync"); 984 system("sync"); 985 system("sync"); 986 system("sync"); 921 987 sleep(2); 922 988 // This last step is probably necessary 923 // 924 // 925 // 926 // 989 // log_to_screen("Re-starting software RAIDs..."); 990 // start_all_raid_devices(mountlist); 991 // system("sync"); system("sync"); system("sync"); 992 // sleep(5); 927 993 // do LVMs now 928 994 log_msg(1, "Creating LVMs"); … … 930 996 wait_until_software_raids_are_prepped("/proc/mdstat", 10); 931 997 log_to_screen("Configuring LVM"); 932 if (!g_text_mode) { newtSuspend(); } 998 if (!g_text_mode) { 999 newtSuspend(); 1000 } 933 1001 /* 934 1002 for(i=0; i<3; i++) … … 943 1011 log_msg(1, "Vacuum-packing..."); 944 1012 */ 945 1013 res = do_my_funky_lvm_stuff(FALSE, TRUE); 946 1014 /* 947 1015 } 948 1016 */ 949 if (!g_text_mode) { newtResume(); } 950 if (!res) { log_to_screen("LVM initialized OK"); } 951 else { log_to_screen("Failed to initialize LVM"); } 1017 if (!g_text_mode) { 1018 newtResume(); 1019 } 1020 if (!res) { 1021 log_to_screen("LVM initialized OK"); 1022 } else { 1023 log_to_screen("Failed to initialize LVM"); 1024 } 952 1025 // retval += res; 953 1026 if (res) { 954 retval ++; 955 } 956 sleep(3); 957 } 958 1027 retval++; 1028 } 1029 sleep(3); 1030 } 959 1031 // do regulars at last 960 sleep(2); 961 1032 sleep(2); // woo! 1033 log_msg(1, "Formatting regulars"); 962 1034 for (lino = 0; lino < mountlist->entries; lino++) { 963 1035 me = &mountlist->el[lino]; // the current mountlist entry … … 966 1038 log_it(tmp); 967 1039 } else if (!strcmp(me->format, "raid")) { 968 sprintf(tmp, "Not formatting %s - it's a raid-let", me->device); 1040 sprintf(tmp, "Not formatting %s - it's a raid-let", 1041 me->device); 969 1042 log_it(tmp); 970 1043 continue; … … 974 1047 continue; 975 1048 } else if (!strncmp(me->device, "/dev/md", 7)) { 976 sprintf(tmp, "Already formatted %s - it's a soft-RAID dev", me->device); 1049 sprintf(tmp, "Already formatted %s - it's a soft-RAID dev", 1050 me->device); 977 1051 log_it(tmp); 978 1052 continue; 979 1053 } else if (!does_file_exist(me->device) 980 && strncmp(me->device, "/dev/hd", 7) 981 && strncmp(me->device, "/dev/sd", 7)) { 982 sprintf(tmp, "Not formatting %s yet - doesn't exist - probably an LVM", me->device); 1054 && strncmp(me->device, "/dev/hd", 7) 1055 && strncmp(me->device, "/dev/sd", 7)) { 1056 sprintf(tmp, 1057 "Not formatting %s yet - doesn't exist - probably an LVM", 1058 me->device); 983 1059 log_it(tmp); 984 1060 continue; … … 986 1062 if (interactively) { 987 1063 // ask user if we should format the current device 988 sprintf(tmp, "Shall I format %s (%s) ?", me->device, me->mountpoint); 1064 sprintf(tmp, "Shall I format %s (%s) ?", me->device, 1065 me->mountpoint); 989 1066 do_it = ask_me_yes_or_no(tmp); 990 1067 } else { … … 1010 1087 if (retval) { 1011 1088 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1012 log_to_screen("Errors occurred during the formatting of your hard drives."); 1089 log_to_screen 1090 ("Errors occurred during the formatting of your hard drives."); 1013 1091 } else { 1014 1092 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1015 1093 } 1016 1094 1017 sprintf(tmp, "format_everything () - %s", (retval) ? "failed!" : "finished successfully"); 1095 sprintf(tmp, "format_everything () - %s", 1096 (retval) ? "failed!" : "finished successfully"); 1018 1097 log_it(tmp); 1019 1098 1020 if (g_partition_table_locked_up > 0) 1021 { 1022 if (retval > 0 && !interactively) 1023 { 1099 if (g_partition_table_locked_up > 0) { 1100 if (retval > 0 && !interactively) { 1024 1101 //123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1025 log_to_screen( 1026 "Partition table locked up %d times. At least one 'mkfs' (format) command", g_partition_table_locked_up); 1027 log_to_screen( 1028 "failed. I think these two events are related. Sometimes, fdisk's ioctl() call"); 1029 log_to_screen( 1030 "to refresh its copy of the partition table causes the kernel to lock the "); 1031 log_to_screen( 1032 "partition table. I believe this has just happened."); 1033 if (ask_me_yes_or_no("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue.")) 1034 { 1035 system("sync"); 1036 system("sync"); 1037 system("sync"); 1038 system("reboot"); 1039 } 1040 } 1041 else 1042 { 1043 log_to_screen( 1044 "Partition table locked up %d time%c. However, disk formatting succeeded.", g_partition_table_locked_up, (g_partition_table_locked_up==1)?'.':'s'); 1045 } 1046 } 1047 newtSuspend(); 1102 log_to_screen 1103 ("Partition table locked up %d times. At least one 'mkfs' (format) command", 1104 g_partition_table_locked_up); 1105 log_to_screen 1106 ("failed. I think these two events are related. Sometimes, fdisk's ioctl() call"); 1107 log_to_screen 1108 ("to refresh its copy of the partition table causes the kernel to lock the "); 1109 log_to_screen 1110 ("partition table. I believe this has just happened."); 1111 if (ask_me_yes_or_no 1112 ("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue.")) 1113 { 1114 system("sync"); 1115 system("sync"); 1116 system("sync"); 1117 system("reboot"); 1118 } 1119 } else { 1120 log_to_screen 1121 ("Partition table locked up %d time%c. However, disk formatting succeeded.", 1122 g_partition_table_locked_up, 1123 (g_partition_table_locked_up == 1) ? '.' : 's'); 1124 } 1125 } 1126 newtSuspend(); 1048 1127 system("clear"); 1049 1128 newtResume(); … … 1061 1140 * @return The number of errors encountered (0 for success). 1062 1141 */ 1063 int make_dummy_partitions(FILE*pout_to_fdisk, char *drivename, int devno_we_must_allow_for) 1142 int make_dummy_partitions(FILE * pout_to_fdisk, char *drivename, 1143 int devno_we_must_allow_for) 1064 1144 { 1065 1145 /** int **************************************************************/ … … 1081 1161 log_it(tmp); 1082 1162 g_maximum_progress++; 1083 res = partition_device(pout_to_fdisk,drivename, 1, 0, "ext2", 32000); 1163 res = 1164 partition_device(pout_to_fdisk, drivename, 1, 0, "ext2", 1165 32000); 1084 1166 retval += res; 1085 1167 previous_devno = 1; … … 1090 1172 } 1091 1173 for (; current_devno < devno_we_must_allow_for; current_devno++) { 1092 sprintf(tmp, "Creating dummy partition %s%d", drivename, current_devno); 1174 sprintf(tmp, "Creating dummy partition %s%d", drivename, 1175 current_devno); 1093 1176 log_it(tmp); 1094 1177 g_maximum_progress++; 1095 res = partition_device(pout_to_fdisk,drivename, current_devno, previous_devno, OSSWAP("ext2", "ufs"), 32000); 1178 res = 1179 partition_device(pout_to_fdisk, drivename, current_devno, 1180 previous_devno, OSSWAP("ext2", "ufs"), 32000); 1096 1181 retval += res; 1097 1182 previous_devno = current_devno; … … 1141 1226 else 1142 1227 fprintf(f, "type: %u\n", lp->d_type); 1143 fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename); 1144 fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname); 1228 fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename), 1229 lp->d_typename); 1230 fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname), 1231 lp->d_packname); 1145 1232 fprintf(f, "flags:"); 1146 1233 if (lp->d_flags & D_REMOVABLE) … … 1161 1248 fprintf(f, "trackskew: %u\n", lp->d_trackskew); 1162 1249 fprintf(f, "cylinderskew: %u\n", lp->d_cylskew); 1163 fprintf(f, "headswitch: %lu\t\t# milliseconds\n", (u_long) lp->d_headswitch); 1164 fprintf(f, "track-to-track seek: %ld\t# milliseconds\n", (u_long) lp->d_trkseek); 1250 fprintf(f, "headswitch: %lu\t\t# milliseconds\n", 1251 (u_long) lp->d_headswitch); 1252 fprintf(f, "track-to-track seek: %ld\t# milliseconds\n", 1253 (u_long) lp->d_trkseek); 1165 1254 fprintf(f, "drivedata: "); 1166 1255 for (i = NDDATA - 1; i >= 0; i--) … … 1172 1261 fprintf(f, "%lu ", (u_long) lp->d_drivedata[j]); 1173 1262 fprintf(f, "\n\n%u partitions:\n", lp->d_npartitions); 1174 fprintf(f, "# size offset fstype [fsize bsize bps/cpg]\n"); 1263 fprintf(f, 1264 "# size offset fstype [fsize bsize bps/cpg]\n"); 1175 1265 pp = lp->d_partitions; 1176 1266 for (i = 0; i < lp->d_npartitions; i++, pp++) { 1177 1267 if (pp->p_size) { 1178 fprintf(f, " %c: %8lu %8lu ", 'a' + i, (u_long) pp->p_size, (u_long) pp->p_offset); 1268 fprintf(f, " %c: %8lu %8lu ", 'a' + i, (u_long) pp->p_size, 1269 (u_long) pp->p_offset); 1179 1270 if (pp->p_fstype < FSMAXTYPES) 1180 1271 fprintf(f, "%8.8s", fstypenames[pp->p_fstype]); … … 1184 1275 1185 1276 case FS_UNUSED: /* XXX */ 1186 fprintf(f, " %5lu %5lu %5.5s ", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag), ""); 1277 fprintf(f, " %5lu %5lu %5.5s ", (u_long) pp->p_fsize, 1278 (u_long) (pp->p_fsize * pp->p_frag), ""); 1187 1279 break; 1188 1280 1189 1281 case FS_BSDFFS: 1190 fprintf(f, " %5lu %5lu %5u ", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag),1191 pp->p_cpg);1282 fprintf(f, " %5lu %5lu %5u ", (u_long) pp->p_fsize, 1283 (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg); 1192 1284 break; 1193 1285 1194 1286 case FS_BSDLFS: 1195 fprintf(f, " %5lu %5lu %5d", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag),1196 pp->p_cpg);1287 fprintf(f, " %5lu %5lu %5d", (u_long) pp->p_fsize, 1288 (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg); 1197 1289 break; 1198 1290 … … 1201 1293 break; 1202 1294 } 1203 fprintf(f, "\t# (Cyl. %4lu", (u_long) (pp->p_offset / lp->d_secpercyl)); 1295 fprintf(f, "\t# (Cyl. %4lu", 1296 (u_long) (pp->p_offset / lp->d_secpercyl)); 1204 1297 if (pp->p_offset % lp->d_secpercyl) 1205 1298 putc('*', f); 1206 1299 else 1207 1300 putc(' ', f); 1208 fprintf(f, "- %lu", (u_long) ((pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl - 1)); 1301 fprintf(f, "- %lu", 1302 (u_long) ((pp->p_offset + pp->p_size + 1303 lp->d_secpercyl - 1) / lp->d_secpercyl - 1304 1)); 1209 1305 if (pp->p_size % lp->d_secpercyl) 1210 1306 putc('*', f); … … 1232 1328 /* New world order */ 1233 1329 if ((ioctl(f, DIOCGMEDIASIZE, &mediasize) != 0) 1234 1330 || (ioctl(f, DIOCGSECTORSIZE, &secsize) != 0)) { 1235 1331 close(f); 1236 1332 return (NULL); … … 1276 1372 return (&loclab); 1277 1373 } 1374 1278 1375 /* End stolen from /usr/src/sbin/disklabel/disklabel.c. */ 1279 1376 … … 1295 1392 * @return The number of errors encountered (0 for success). 1296 1393 */ 1297 int label_drive_or_slice(struct mountlist_itself *mountlist, char *drivename, struct disklabel *ret) 1394 int label_drive_or_slice(struct mountlist_itself *mountlist, 1395 char *drivename, struct disklabel *ret) 1298 1396 { 1299 1397 char subdev_str[MAX_STR_LEN]; … … 1319 1417 lp->d_partitions[c - 'a'].p_cpg = 0; 1320 1418 if (!strcmp(mountlist->el[idx].format, "ufs") 1321 1322 1419 || !strcmp(mountlist->el[idx].format, "ffs") 1420 || !strcmp(mountlist->el[idx].format, "4.2BSD")) { 1323 1421 lp->d_partitions[c - 'a'].p_fstype = FS_BSDFFS; 1324 1422 lp->d_partitions[c - 'a'].p_fsize = 2048; … … 1326 1424 lp->d_partitions[c - 'a'].p_cpg = 64; 1327 1425 } else if (!strcasecmp(mountlist->el[idx].format, "raid") 1328 || !strcasecmp(mountlist->el[idx].format, "vinum")) {1426 || !strcasecmp(mountlist->el[idx].format, "vinum")) { 1329 1427 lp->d_partitions[c - 'a'].p_fstype = FS_VINUM; 1330 1428 } else if (!strcmp(mountlist->el[idx].format, "swap")) { … … 1347 1445 for (lastone = i - 1; lastone >= 0; lastone--) { 1348 1446 if ((lp->d_partitions[lastone].p_size) 1349 1447 && (lastone != RAW_PART)) 1350 1448 break; 1351 1449 } 1352 lp->d_partitions[i].p_offset = lp->d_partitions[lastone].p_offset + lp->d_partitions[lastone].p_size; 1353 } 1354 if (lp->d_partitions[lo].p_offset + lp->d_partitions[lo].p_size > lp->d_secperunit) { 1355 lp->d_partitions[lo].p_size = lp->d_secperunit - lp->d_partitions[lo].p_offset; 1450 lp->d_partitions[i].p_offset = 1451 lp->d_partitions[lastone].p_offset + 1452 lp->d_partitions[lastone].p_size; 1453 } 1454 if (lp->d_partitions[lo].p_offset + lp->d_partitions[lo].p_size > 1455 lp->d_secperunit) { 1456 lp->d_partitions[lo].p_size = 1457 lp->d_secperunit - lp->d_partitions[lo].p_offset; 1356 1458 } 1357 1459 … … 1361 1463 sprintf(command, "disklabel -wr %s auto", canonical_name(drivename)); 1362 1464 retval += run_program_and_log_output(command, TRUE); 1363 sprintf(command, "disklabel -R %s /tmp/disklabel", canonical_name(drivename)); 1465 sprintf(command, "disklabel -R %s /tmp/disklabel", 1466 canonical_name(drivename)); 1364 1467 retval += run_program_and_log_output(command, TRUE); 1365 1468 if (ret) … … 1384 1487 int retval = 0; 1385 1488 int i; 1386 FILE *pout_to_fdisk=NULL;1387 1489 FILE *pout_to_fdisk = NULL; 1490 1388 1491 #ifdef __FreeBSD__ 1389 1492 bool fbsd_part = FALSE; … … 1407 1510 malloc_string(format); 1408 1511 malloc_string(tmp); 1409 1512 1410 1513 sprintf(tmp, "Partitioning drive %s", drivename); 1411 1514 log_it(tmp); 1412 1515 1413 #if __FreeBSD__ 1414 1516 #if __FreeBSD__ 1517 log_it("(Not opening fdisk now; that's the Linux guy's job)"); 1415 1518 pout_to_fdisk = NULL; 1416 1519 #else 1417 1520 make_hole_for_file(FDISK_LOG); 1418 1521 #ifdef __IA64__ 1419 sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG); 1522 sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, 1523 FDISK_LOG); 1420 1524 #else 1421 1525 sprintf(tmp, "fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG); 1422 1526 #endif 1423 1527 pout_to_fdisk = popen(tmp, "w"); 1424 if (!pout_to_fdisk) { 1425 log_to_screen("Cannot call fdisk to configure %s", drivename); 1528 if (!pout_to_fdisk) { 1529 log_to_screen("Cannot call fdisk to configure %s", drivename); 1426 1530 paranoid_free(device_str); 1427 1531 paranoid_free(format); 1428 1532 paranoid_free(tmp); 1429 return (1);1533 return (1); 1430 1534 } 1431 1535 #endif … … 1445 1549 for (c = 'a'; c <= 'z'; c++) { 1446 1550 sprintf(subdev_str, "%s%c", drivename, c); 1447 if (find_device_in_mountlist(mountlist, subdev_str) > 0) { 1551 if (find_device_in_mountlist(mountlist, subdev_str) > 1552 0) { 1448 1553 fbsd_part = TRUE; 1449 1554 } … … 1451 1556 if (fbsd_part) { 1452 1557 int r = label_drive_or_slice(mountlist, 1453 1454 1558 drivename, 1559 0); 1455 1560 char command[MAX_STR_LEN]; 1456 sprintf(command, "disklabel -B %s", basename(drivename)); 1561 sprintf(command, "disklabel -B %s", 1562 basename(drivename)); 1457 1563 if (system(command)) { 1458 log_to_screen("Warning! Unable to make the drive bootable."); 1564 log_to_screen 1565 ("Warning! Unable to make the drive bootable."); 1459 1566 } 1460 1567 paranoid_free(device_str); … … 1501 1608 #if __FreeBSD__ 1502 1609 // FreeBSD doesn't let you write to blk devices in <512byte chunks. 1503 // 1504 // 1610 // sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename); 1611 // if (run_program_and_log_output(tmp, TRUE)) { 1505 1612 file = open(drivename, O_WRONLY); 1506 1613 if (!file) { 1507 sprintf(tmp, "Warning - unable to open %s for wiping it's partition table", drivename); 1614 sprintf(tmp, 1615 "Warning - unable to open %s for wiping it's partition table", 1616 drivename); 1508 1617 log_to_screen(tmp); 1509 1618 } 1510 1619 1511 for (i=0; i<512; i++) { 1512 if ( !write(file, "\0", 1) ) { 1513 sprintf(tmp, "Warning - unable to write to %s", drivename); 1620 for (i = 0; i < 512; i++) { 1621 if (!write(file, "\0", 1)) { 1622 sprintf(tmp, "Warning - unable to write to %s", 1623 drivename); 1514 1624 log_to_screen(tmp); 1515 1625 } … … 1518 1628 #else 1519 1629 iamhere("New, kernel-friendly partition remover"); 1520 for(i=20;i>0;i--) 1521 { 1522 fprintf(pout_to_fdisk, "d\n%d\n", i); 1523 fflush(pout_to_fdisk); 1524 } 1525 // sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename); 1526 // run_program_and_log_output(tmp, 1); 1527 #endif 1630 for (i = 20; i > 0; i--) { 1631 fprintf(pout_to_fdisk, "d\n%d\n", i); 1632 fflush(pout_to_fdisk); 1633 } 1634 // sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename); 1635 // run_program_and_log_output(tmp, 1); 1636 #endif 1528 1637 if (current_devno > 1) { 1529 previous_devno = make_dummy_partitions(pout_to_fdisk,drivename, current_devno); 1638 previous_devno = 1639 make_dummy_partitions(pout_to_fdisk, drivename, 1640 current_devno); 1530 1641 } 1531 1642 } … … 1534 1645 #endif 1535 1646 1536 strcpy(format, mountlist->el[lino].format);1537 partsize = mountlist->el[lino].size;1647 strcpy(format, mountlist->el[lino].format); 1648 partsize = mountlist->el[lino].size; 1538 1649 1539 1650 #ifdef __FreeBSD__ … … 1542 1653 1543 1654 if (current_devno == 5 && previous_devno == 4) { 1544 log_to_screen("You must leave at least one partition spare as the Extended partition."); 1655 log_to_screen 1656 ("You must leave at least one partition spare as the Extended partition."); 1545 1657 paranoid_free(device_str); 1546 1658 paranoid_free(format); … … 1549 1661 } 1550 1662 1551 retval += partition_device(pout_to_fdisk, drivename, current_devno, previous_devno, format, partsize); 1663 retval += 1664 partition_device(pout_to_fdisk, drivename, current_devno, 1665 previous_devno, format, partsize); 1552 1666 1553 1667 #ifdef __FreeBSD__ … … 1556 1670 retval += label_drive_or_slice(mountlist, device_str, 0); 1557 1671 if (system(tmp)) { 1558 log_to_screen("Warning! Unable to make the slice bootable."); 1672 log_to_screen 1673 ("Warning! Unable to make the slice bootable."); 1559 1674 } 1560 1675 } … … 1564 1679 } 1565 1680 1566 if (pout_to_fdisk) 1567 { 1681 if (pout_to_fdisk) { 1568 1682 // mark relevant partition as bootable 1569 sprintf(tmp, "a\n%s\n", call_program_and_get_last_line_of_output("make-me-bootable /tmp/mountlist.txt dummy")); 1683 sprintf(tmp, "a\n%s\n", 1684 call_program_and_get_last_line_of_output 1685 ("make-me-bootable /tmp/mountlist.txt dummy")); 1570 1686 fput_string_one_char_at_a_time(pout_to_fdisk, tmp); 1571 1687 // close fdisk 1572 1688 fput_string_one_char_at_a_time(pout_to_fdisk, "w\n"); 1573 1689 system("sync"); 1574 paranoid_pclose(pout_to_fdisk); 1575 log_msg(0, "------------------- fdisk.log looks like this ------------------"); 1690 paranoid_pclose(pout_to_fdisk); 1691 log_msg(0, 1692 "------------------- fdisk.log looks like this ------------------"); 1576 1693 sprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE); 1577 1694 system(tmp); 1578 log_msg(0, "------------------- end of fdisk.log... word! ------------------"); 1695 log_msg(0, 1696 "------------------- end of fdisk.log... word! ------------------"); 1579 1697 sprintf(tmp, "tail -n6 %s | fgrep \"16: \"", FDISK_LOG); 1580 if (!run_program_and_log_output(tmp, 5)) 1581 {1582 g_partition_table_locked_up++;1583 log_to_screen("A flaw in the Linux kernel has locked the partition table.");1584 1698 if (!run_program_and_log_output(tmp, 5)) { 1699 g_partition_table_locked_up++; 1700 log_to_screen 1701 ("A flaw in the Linux kernel has locked the partition table."); 1702 } 1585 1703 } 1586 1704 paranoid_free(device_str); … … 1599 1717 * @return 0 for success, nonzero for failure. 1600 1718 */ 1601 int partition_device(FILE*pout_to_fdisk, const char *drive, int partno, int prev_partno, const char *format, long long partsize) 1719 int partition_device(FILE * pout_to_fdisk, const char *drive, int partno, 1720 int prev_partno, const char *format, 1721 long long partsize) 1602 1722 { 1603 1723 /** int **************************************************************/ … … 1624 1744 malloc_string(logfile); 1625 1745 malloc_string(output); 1626 1746 1627 1747 assert_string_is_neither_NULL_nor_zerolength(drive); 1628 1748 assert(format != NULL); 1629 1749 1630 log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting", drive, partno, prev_partno, format, partsize); 1750 log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting", 1751 drive, partno, prev_partno, format, partsize); 1631 1752 1632 1753 if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) { … … 1644 1765 sprintf(tmp, "Partitioning device %s (max size)", partition_name); 1645 1766 } else { 1646 sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name, (long long) partsize / 1024); 1767 sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name, 1768 (long long) partsize / 1024); 1647 1769 } 1648 1770 update_progress_form(tmp); … … 1650 1772 1651 1773 if (is_this_device_mounted(partition_name)) { 1652 sprintf(tmp, "%s is mounted, and should not be partitioned", partition_name); 1774 sprintf(tmp, "%s is mounted, and should not be partitioned", 1775 partition_name); 1653 1776 log_to_screen(tmp); 1654 1777 paranoid_free(program); … … 1671 1794 p = (char *) strrchr(partition_name, '/'); 1672 1795 sprintf(logfile, "/tmp/fdisk.log.%s", ++p); 1673 sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE); 1796 sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, 1797 MONDO_LOGFILE); 1674 1798 1675 1799 output[0] = '\0'; … … 1681 1805 part_table_fmt = which_partition_format(drive); 1682 1806 /* GPT allows more than 4 primary partitions */ 1683 if ((prev_partno >= 4) && (strcmp(part_table_fmt,"MBR") == 0)) { 1684 log_to_screen("You need to leave at least one partition free, for 'extended/logical'"); 1807 if ((prev_partno >= 4) && (strcmp(part_table_fmt, "MBR") == 0)) { 1808 log_to_screen 1809 ("You need to leave at least one partition free, for 'extended/logical'"); 1685 1810 paranoid_free(program); 1686 1811 paranoid_free(partition_name); … … 1690 1815 return (1); 1691 1816 } else { 1692 sprintf(output + strlen(output), "n\ne\n%d\n\n\n", prev_partno + 1); 1817 sprintf(output + strlen(output), "n\ne\n%d\n\n\n", 1818 prev_partno + 1); 1693 1819 } 1694 1820 } … … 1697 1823 strcat(output + strlen(output), "\n"); /*start block (ENTER for next free blk */ 1698 1824 if (partsize > 0) { 1699 if (!strcmp(format, "7")) { log_msg(1, "Adding 512K, just in case"); partsize+=512; } 1825 if (!strcmp(format, "7")) { 1826 log_msg(1, "Adding 512K, just in case"); 1827 partsize += 512; 1828 } 1700 1829 sprintf(output + strlen(output), "+%lldK", (long long) (partsize)); 1701 1830 } … … 1714 1843 1715 1844 1716 if (pout_to_fdisk) 1717 { 1845 if (pout_to_fdisk) { 1718 1846 log_msg(1, "Doing the new all-in-one fdisk thing"); 1719 1847 log_msg(1, "output = '%s'", output); … … 1721 1849 fput_string_one_char_at_a_time(pout_to_fdisk, "\n\np\n"); 1722 1850 strcpy(tmp, last_line_of_file(FDISK_LOG)); 1723 if (strstr(tmp, " (m ")) 1724 { 1851 if (strstr(tmp, " (m ")) { 1725 1852 log_msg(1, "Successfully created %s%d", drive, partno); 1726 } 1727 else 1728 { 1853 } else { 1729 1854 log_msg(1, "last line = %s", tmp); 1730 log_msg(1, "Failed to create %s%d; sending 'Enter'...", drive, partno); 1731 } 1732 if (!retval) 1733 { 1734 log_msg(1, "Trying to set %s%d's partition type now", drive, partno); 1735 retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize); 1736 if (retval) 1737 { 1855 log_msg(1, "Failed to create %s%d; sending 'Enter'...", drive, 1856 partno); 1857 } 1858 if (!retval) { 1859 log_msg(1, "Trying to set %s%d's partition type now", drive, 1860 partno); 1861 retval = 1862 set_partition_type(pout_to_fdisk, drive, partno, format, 1863 partsize); 1864 if (retval) { 1738 1865 log_msg(1, "Failed. Trying again..."); 1739 retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize); 1740 } 1741 } 1742 if (retval) { log_msg(1, "...but failed to set type"); } 1743 } 1744 else 1745 { 1866 retval = 1867 set_partition_type(pout_to_fdisk, drive, partno, 1868 format, partsize); 1869 } 1870 } 1871 if (retval) { 1872 log_msg(1, "...but failed to set type"); 1873 } 1874 } else { 1746 1875 strcat(output, "w\n\n"); 1747 if (g_fprep) { fprintf(g_fprep, "echo \"%s\" | %s\n", output, program); } 1876 if (g_fprep) { 1877 fprintf(g_fprep, "echo \"%s\" | %s\n", output, program); 1878 } 1748 1879 /* write to disk; close fdisk's stream */ 1749 1880 if (!(fout = popen(program, "w"))) { … … 1756 1887 log_it("Vaccum-packing"); 1757 1888 g_current_progress--; 1758 res = partition_device(pout_to_fdisk, drive, partno, prev_partno, format, -1); 1889 res = 1890 partition_device(pout_to_fdisk, drive, partno, prev_partno, 1891 format, -1); 1759 1892 if (res) { 1760 1893 sprintf(tmp, "Failed to vacuum-pack %s", partition_name); … … 1766 1899 } 1767 1900 if (does_partition_exist(drive, partno)) { 1768 retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize); 1901 retval = 1902 set_partition_type(pout_to_fdisk, drive, partno, format, 1903 partsize); 1769 1904 if (retval) { 1770 sprintf(tmp, "Partitioned %s but failed to set its type", partition_name); 1905 sprintf(tmp, "Partitioned %s but failed to set its type", 1906 partition_name); 1771 1907 log_it(tmp); 1772 1908 } else { 1773 1909 if (partsize > 0) { 1774 sprintf(tmp, "Partition %s created+configured OK", partition_name); 1910 sprintf(tmp, "Partition %s created+configured OK", 1911 partition_name); 1775 1912 log_to_screen(tmp); 1776 1913 } else { … … 1778 1915 } 1779 1916 } 1780 1917 } else { 1781 1918 sprintf(tmp, "Failed to partition %s", partition_name); 1782 1919 if (partsize > 0) { … … 1830 1967 /* mountlist=&new_mtlist; */ 1831 1968 /* extrapolate_mountlist_to_include_raid_partitions(mountlist,orig_mtlist); */ 1832 log_msg(0,"Mountlist, including the partitions incorporated in RAID devices:-"); 1969 log_msg(0, 1970 "Mountlist, including the partitions incorporated in RAID devices:-"); 1833 1971 for (i = 0; i < mountlist->entries; i++) { 1834 1972 log_it(mountlist->el[i].device); … … 1837 1975 } 1838 1976 log_msg(0, "Stopping all LVMs, just in case"); 1839 if (!g_text_mode) { newtSuspend(); } 1840 do_my_funky_lvm_stuff(TRUE, FALSE); // just remove old partitions 1841 if (!g_text_mode) { newtResume(); } 1977 if (!g_text_mode) { 1978 newtSuspend(); 1979 } 1980 do_my_funky_lvm_stuff(TRUE, FALSE); // just remove old partitions 1981 if (!g_text_mode) { 1982 newtResume(); 1983 } 1842 1984 log_msg(0, "Stopping all software RAID devices, just in case"); 1843 1985 stop_all_raid_devices(mountlist); 1844 1986 log_msg(0, "Done."); 1845 1987 1846 1988 /* 1847 1989 if (does_file_exist("/tmp/i-want-my-lvm")) … … 1851 1993 */ 1852 1994 1853 open_progress_form("Partitioning devices", "I am now going to partition all your drives.", 1854 "This should not take more than five minutes.", "", mountlist->entries); 1995 open_progress_form("Partitioning devices", 1996 "I am now going to partition all your drives.", 1997 "This should not take more than five minutes.", "", 1998 mountlist->entries); 1855 1999 1856 2000 make_list_of_drives_in_mountlist(mountlist, drivelist); … … 1864 2008 if (retval) { 1865 2009 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1866 log_to_screen("Errors occurred during the partitioning of your hard drives."); 2010 log_to_screen 2011 ("Errors occurred during the partitioning of your hard drives."); 1867 2012 } else { 1868 2013 mvaddstr_and_log_it(g_currentY++, 74, "Done."); … … 1890 2035 * @return 0 for success, nonzero for failure. 1891 2036 */ 1892 int set_partition_type(FILE *pout_to_fdisk, const char *drive, int partno, const char *format, long long partsize) 2037 int set_partition_type(FILE * pout_to_fdisk, const char *drive, int partno, 2038 const char *format, long long partsize) 1893 2039 { 1894 2040 /** buffers *********************************************************/ 1895 1896 1897 1898 1899 1900 2041 char *partition; 2042 char *command; 2043 char *output; 2044 char *tmp; 2045 char *partcode; 2046 char *logfile; 1901 2047 1902 2048 /** pointers *********************************************************/ … … 1912 2058 assert(format != NULL); 1913 2059 1914 1915 1916 1917 1918 1919 2060 malloc_string(partition); 2061 malloc_string(command); 2062 malloc_string(output); 2063 malloc_string(tmp); 2064 malloc_string(partcode); 2065 malloc_string(logfile); 1920 2066 1921 2067 build_partition_name(partition, drive, partno); … … 1930 2076 strcpy(partcode, "b"); 1931 2077 } 1932 } else if (strcmp(format, "ext2") == 0 || strcmp(format, "reiserfs") == 0 || strcmp(format, "ext3") == 0 1933 || strcmp(format, "xfs") == 0 || strcmp(format, "jfs") == 0) { 2078 } else if (strcmp(format, "ext2") == 0 2079 || strcmp(format, "reiserfs") == 0 2080 || strcmp(format, "ext3") == 0 || strcmp(format, "xfs") == 0 2081 || strcmp(format, "jfs") == 0) { 1934 2082 strcpy(partcode, "83"); 1935 2083 } else if (strcmp(format, "minix") == 0) { … … 1938 2086 strcpy(partcode, "fd"); 1939 2087 } else if ((strcmp(format, "ufs") == 0) 1940 || (strcmp(format, "ffs") == 0)) { /* raid autodetect */2088 || (strcmp(format, "ffs") == 0)) { /* raid autodetect */ 1941 2089 strcpy(partcode, "a5"); 1942 2090 } else if (strcmp(format, "lvm") == 0) { … … 1948 2096 } else { 1949 2097 /* probably an image */ 1950 sprintf(tmp, "Unknown format ('%s') - using supplied string anyway", format); 2098 sprintf(tmp, 2099 "Unknown format ('%s') - using supplied string anyway", 2100 format); 1951 2101 mvaddstr_and_log_it(g_currentY++, 0, tmp); 1952 2102 #ifdef __FreeBSD__ 1953 strcpy(partcode, format); 2103 strcpy(partcode, format); // was a5 1954 2104 #else 1955 strcpy(partcode, format); // was 83 1956 #endif 1957 } 1958 sprintf(tmp, "Setting %s's type to %s (%s)", partition, format, partcode); 2105 strcpy(partcode, format); // was 83 2106 #endif 2107 } 2108 sprintf(tmp, "Setting %s's type to %s (%s)", partition, format, 2109 partcode); 1959 2110 log_msg(1, tmp); 1960 2111 if (partcode[0] != '\0' && strcmp(partcode, "83")) { /* no need to set type if 83: 83 is default */ 1961 1962 if (pout_to_fdisk) 1963 { 2112 2113 if (pout_to_fdisk) { 1964 2114 res = 0; 1965 2115 fput_string_one_char_at_a_time(pout_to_fdisk, "t\n"); 1966 if (partno > 1 || strstr(last_line_of_file(FDISK_LOG), " (1-4)"))1967 {2116 if (partno > 1 2117 || strstr(last_line_of_file(FDISK_LOG), " (1-4)")) { 1968 2118 log_msg(5, "Specifying partno (%d) - yay", partno); 1969 2119 sprintf(tmp, "%d\n", partno); 1970 2120 fput_string_one_char_at_a_time(pout_to_fdisk, tmp); 1971 log_msg(5, "A - last line = '%s'", last_line_of_file(FDISK_LOG)); 1972 } 1973 2121 log_msg(5, "A - last line = '%s'", 2122 last_line_of_file(FDISK_LOG)); 2123 } 2124 1974 2125 sprintf(tmp, "%s\n", partcode); 1975 2126 fput_string_one_char_at_a_time(pout_to_fdisk, tmp); 1976 log_msg(5, "B - last line = '%s'", last_line_of_file(FDISK_LOG)); 2127 log_msg(5, "B - last line = '%s'", 2128 last_line_of_file(FDISK_LOG)); 1977 2129 fput_string_one_char_at_a_time(pout_to_fdisk, "\n"); 1978 log_msg(5, "C - last line = '%s'", last_line_of_file(FDISK_LOG)); 1979 2130 log_msg(5, "C - last line = '%s'", 2131 last_line_of_file(FDISK_LOG)); 2132 1980 2133 strcpy(tmp, last_line_of_file(FDISK_LOG)); 1981 if (!strstr(tmp, " (m ")) 1982 { 1983 log_msg(1, "last line = '%s'; part type set failed", tmp); 1984 res++; 1985 fput_string_one_char_at_a_time(pout_to_fdisk,"\n"); 1986 } 1987 fput_string_one_char_at_a_time(pout_to_fdisk,"p\n"); 1988 } 1989 else 1990 { 2134 if (!strstr(tmp, " (m ")) { 2135 log_msg(1, "last line = '%s'; part type set failed", tmp); 2136 res++; 2137 fput_string_one_char_at_a_time(pout_to_fdisk, "\n"); 2138 } 2139 fput_string_one_char_at_a_time(pout_to_fdisk, "p\n"); 2140 } else { 1991 2141 sprintf(output, "t\n%d\n%s\n", partno, partcode); 1992 2142 strcat(output, "w\n"); 1993 sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE); 2143 sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive, 2144 MONDO_LOGFILE, MONDO_LOGFILE); 1994 2145 log_msg(5, "output = '%s'", output); 1995 2146 log_msg(5, "partno=%d; partcode=%s", partno, partcode); … … 2005 2156 } 2006 2157 } 2007 if (res) 2008 { 2009 log_OS_error(command); 2010 } 2011 } 2012 2013 paranoid_free(partition); 2014 paranoid_free(command); 2015 paranoid_free(output); 2016 paranoid_free(tmp); 2017 paranoid_free(partcode); 2018 paranoid_free(logfile); 2019 2020 return (res); 2158 if (res) { 2159 log_OS_error(command); 2160 } 2161 } 2162 2163 paranoid_free(partition); 2164 paranoid_free(command); 2165 paranoid_free(output); 2166 paranoid_free(tmp); 2167 paranoid_free(partcode); 2168 paranoid_free(logfile); 2169 2170 return (res); 2021 2171 } 2022 2172 … … 2035 2185 assert_string_is_neither_NULL_nor_zerolength(raid_device); 2036 2186 malloc_string(program); 2037 2187 2038 2188 #ifdef __FreeBSD__ 2039 2189 if (is_this_device_mounted(raid_device)) { … … 2048 2198 log_msg(1, "program = %s", program); 2049 2199 res = run_program_and_log_output(program, 1); 2050 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 2051 if (res) { log_msg(1, "Warning - failed to start RAID device %s", raid_device); } 2200 if (g_fprep) { 2201 fprintf(g_fprep, "%s\n", program); 2202 } 2203 if (res) { 2204 log_msg(1, "Warning - failed to start RAID device %s", 2205 raid_device); 2206 } 2052 2207 retval += res; 2053 2208 sleep(1); … … 2075 2230 assert_string_is_neither_NULL_nor_zerolength(raid_device); 2076 2231 malloc_string(program); 2077 2232 2078 2233 #ifdef __FreeBSD__ 2079 2234 if (is_this_device_mounted(raid_device)) { … … 2088 2243 log_msg(1, "program = %s", program); 2089 2244 res = run_program_and_log_output(program, 1); 2090 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 2091 if (res) { log_msg(1, "Warning - failed to stop RAID device %s", raid_device); } 2245 if (g_fprep) { 2246 fprintf(g_fprep, "%s\n", program); 2247 } 2248 if (res) { 2249 log_msg(1, "Warning - failed to stop RAID device %s", raid_device); 2250 } 2092 2251 retval += res; 2093 2252 return (retval); … … 2098 2257 { 2099 2258 int i; 2100 int retval =0;2259 int retval = 0; 2101 2260 int res; 2102 2103 for(i=0; i<mountlist->entries; i++) 2104 { 2105 if (!strncmp(mountlist->el[i].device, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) 2106 { 2107 log_msg(1, "Starting %s", mountlist->el[i].device); 2108 res = start_raid_device(mountlist->el[i].device); 2109 retval += res; 2110 } 2111 } 2112 if (retval) { log_msg(1, "Started all s/w raid devices OK"); } 2113 else { log_msg(1, "Failed to start some/all s/w raid devices"); } 2114 return(retval); 2261 2262 for (i = 0; i < mountlist->entries; i++) { 2263 if (!strncmp 2264 (mountlist->el[i].device, RAID_DEVICE_STUB, 2265 strlen(RAID_DEVICE_STUB))) { 2266 log_msg(1, "Starting %s", mountlist->el[i].device); 2267 res = start_raid_device(mountlist->el[i].device); 2268 retval += res; 2269 } 2270 } 2271 if (retval) { 2272 log_msg(1, "Started all s/w raid devices OK"); 2273 } else { 2274 log_msg(1, "Failed to start some/all s/w raid devices"); 2275 } 2276 return (retval); 2115 2277 } 2116 2278 … … 2149 2311 for (i = 0; i < 3; i++) { 2150 2312 #ifdef __FreeBSD__ 2151 fin = popen("vinum list | grep '^[PVS]' | sed 's/S/1/;s/P/2/;s/V/3/' | sort | cut -d' ' -f2", "r"); 2313 fin = 2314 popen 2315 ("vinum list | grep '^[PVS]' | sed 's/S/1/;s/P/2/;s/V/3/' | sort | cut -d' ' -f2", 2316 "r"); 2152 2317 if (!fin) { 2153 2318 paranoid_free(dev); … … 2155 2320 return (1); 2156 2321 } 2157 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); fgets(incoming, MAX_STR_LEN - 1, fin)) { 2322 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); 2323 fgets(incoming, MAX_STR_LEN - 1, fin)) { 2158 2324 retval += stop_raid_device(incoming); 2159 2325 } … … 2166 2332 return (1); 2167 2333 } 2168 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); fgets(incoming, MAX_STR_LEN - 1, fin)) { 2169 for (p = incoming; *p != '\0' && (*p != 'm' || *(p + 1) != 'd' || !isdigit(*(p + 2))); p++); 2334 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); 2335 fgets(incoming, MAX_STR_LEN - 1, fin)) { 2336 for (p = incoming; 2337 *p != '\0' && (*p != 'm' || *(p + 1) != 'd' 2338 || !isdigit(*(p + 2))); p++); 2170 2339 if (*p != '\0') { 2171 2340 sprintf(dev, "/dev/%s", p); … … 2178 2347 } 2179 2348 paranoid_fclose(fin); 2180 if (retval) { log_msg(1, "Warning - unable to stop some RAID devices"); } 2349 if (retval) { 2350 log_msg(1, "Warning - unable to stop some RAID devices"); 2351 } 2181 2352 paranoid_free(dev); 2182 2353 paranoid_free(incoming); 2183 system("sync"); system("sync"); system("sync"); 2354 system("sync"); 2355 system("sync"); 2356 system("sync"); 2184 2357 sleep(1); 2185 2358 return (retval); … … 2236 2409 sprintf(program, "mkfs -t %s -c", format); // -c checks for bad blocks 2237 2410 #endif 2238 sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format, program); 2411 sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format, 2412 program); 2239 2413 log_it(tmp); 2240 2414 res = 0; … … 2253 2427 */ 2254 2428 long calc_orig_size_of_drive_from_mountlist(struct mountlist_itself 2255 2429 *mountlist, char *drive_name) 2256 2430 { 2257 2431 /** long ************************************************************/ … … 2270 2444 assert_string_is_neither_NULL_nor_zerolength(drive_name); 2271 2445 2272 for (original_size_of_drive = 0, partno = 0; partno < mountlist->entries; partno++) { 2273 if (strncmp(mountlist->el[partno].device, drive_name, strlen(drive_name)) == 0) { 2446 for (original_size_of_drive = 0, partno = 0; 2447 partno < mountlist->entries; partno++) { 2448 if (strncmp 2449 (mountlist->el[partno].device, drive_name, 2450 strlen(drive_name)) == 0) { 2274 2451 original_size_of_drive += mountlist->el[partno].size; 2275 2452 } else { … … 2296 2473 */ 2297 2474 void resize_drive_proportionately_to_suit_new_drives(struct mountlist_itself 2298 *mountlist, char *drive_name) 2475 *mountlist, 2476 char *drive_name) 2299 2477 { 2300 2478 /**buffers **********************************************************/ … … 2303 2481 /** int *************************************************************/ 2304 2482 int partno, lastpart; 2305 2483 /** remove driveno, noof_drives stan benoit apr 2002**/ 2306 2484 2307 2485 /** float ***********************************************************/ 2308 2486 float factor; 2309 2487 float new_size; 2310 // 2488 // float newcylinderno; 2311 2489 2312 2490 /** long *************************************************************/ … … 2314 2492 long current_size_of_drive = 0; 2315 2493 long original_size_of_drive = 0; 2316 long final_size; /* all in Megabytes */2494 long final_size; /* all in Megabytes */ 2317 2495 struct mountlist_reference *drivemntlist; 2318 2496 … … 2326 2504 2327 2505 if (strlen(drive_name) >= strlen(RAID_DEVICE_STUB)) { 2328 if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)) == 0) { 2506 if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)) 2507 == 0) { 2329 2508 paranoid_free(tmp); 2330 2509 return; … … 2338 2517 2339 2518 current_size_of_drive = get_phys_size_of_drive(drive_name); 2340 2519 2341 2520 if (current_size_of_drive <= 0) { 2342 2521 log_it("Not resizing to match %s - can't find drive", drive_name); … … 2344 2523 return; 2345 2524 } 2346 sprintf(tmp, "Expanding entries to suit drive %s (%ld MB)", drive_name, current_size_of_drive); 2525 sprintf(tmp, "Expanding entries to suit drive %s (%ld MB)", drive_name, 2526 current_size_of_drive); 2347 2527 log_to_screen(tmp); 2348 2528 2349 drivemntlist = malloc(sizeof (struct mountlist_reference)); 2350 drivemntlist->el = malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES); 2529 drivemntlist = malloc(sizeof(struct mountlist_reference)); 2530 drivemntlist->el = 2531 malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES); 2351 2532 2352 2533 if (!drivemntlist) { … … 2361 2542 2362 2543 if (original_size_of_drive <= 0) { 2363 sprintf(tmp, "Cannot resize %s's entries. Drive not found.", drive_name); 2544 sprintf(tmp, "Cannot resize %s's entries. Drive not found.", 2545 drive_name); 2364 2546 log_to_screen(tmp); 2365 2547 paranoid_free(tmp); 2366 2548 return; 2367 2549 } 2368 factor = (float) (current_size_of_drive) / (float) (original_size_of_drive); 2369 sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f", drive_name, original_size_of_drive, current_size_of_drive, 2370 factor); 2550 factor = 2551 (float) (current_size_of_drive) / (float) (original_size_of_drive); 2552 sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f", 2553 drive_name, original_size_of_drive, current_size_of_drive, 2554 factor); 2371 2555 log_to_screen(tmp); 2372 2556 2373 lastpart = drivemntlist->entries -1;2557 lastpart = drivemntlist->entries - 1; 2374 2558 for (partno = 0; partno < drivemntlist->entries; partno++) { 2375 2559 /* the 'atoi' thing is to make sure we don't try to resize _images_, whose formats will be numeric */ 2376 if ( !atoi(drivemntlist->el[partno]->format)) {2560 if (!atoi(drivemntlist->el[partno]->format)) { 2377 2561 new_size = (float) (drivemntlist->el[partno]->size) * factor; 2378 2562 } else { 2379 2563 new_size = drivemntlist->el[partno]->size; 2380 2564 } 2381 2565 2382 2566 if (!strcmp(drivemntlist->el[partno]->mountpoint, "image")) { 2383 2567 log_msg(1, "Skipping %s (%s) because it's an image", 2384 2385 2386 newsizL = (long) new_size; 2568 drivemntlist->el[partno]->device, 2569 drivemntlist->el[partno]->mountpoint); 2570 newsizL = (long) new_size; // It looks wrong but it's not 2387 2571 } else { 2388 2572 newsizL = (long) new_size; 2389 2573 } 2390 sprintf(tmp, "Changing %s from %lld KB to %ld KB", drivemntlist->el[partno]->device, drivemntlist->el[partno]->size,newsizL); 2574 sprintf(tmp, "Changing %s from %lld KB to %ld KB", 2575 drivemntlist->el[partno]->device, 2576 drivemntlist->el[partno]->size, newsizL); 2391 2577 log_to_screen(tmp); 2392 2578 drivemntlist->el[partno]->size = newsizL; … … 2406 2592 */ 2407 2593 void resize_mountlist_proportionately_to_suit_new_drives(struct mountlist_itself 2408 *mountlist)2594 *mountlist) 2409 2595 { 2410 2596 /** buffers *********************************************************/ … … 2420 2606 2421 2607 if (g_mountlist_fname[0] == '\0') { 2422 log_it ("resize_mountlist_prop...() - warning - mountlist fname is blank"); 2423 log_it ("That does NOT affect the functioning of this subroutine."); 2424 log_it ("--- Hugo, 2002/11/20"); 2608 log_it 2609 ("resize_mountlist_prop...() - warning - mountlist fname is blank"); 2610 log_it("That does NOT affect the functioning of this subroutine."); 2611 log_it("--- Hugo, 2002/11/20"); 2425 2612 } 2426 2613 iamhere("Resizing mountlist"); … … 2428 2615 iamhere("Back from MLoDiM"); 2429 2616 for (driveno = 0; driveno < drivelist->entries; driveno++) { 2430 resize_drive_proportionately_to_suit_new_drives(mountlist, drivelist->el[driveno].device); 2617 resize_drive_proportionately_to_suit_new_drives(mountlist, 2618 drivelist-> 2619 el[driveno]. 2620 device); 2431 2621 } 2432 2622 log_to_screen("Mountlist adjusted to suit current hard drive(s)"); … … 2442 2632 * @author Ralph Grewe 2443 2633 */ 2444 void create_mountlist_for_drive(struct mountlist_itself *mountlist, char *drive_name, struct mountlist_reference *drivemntlist) { 2634 void create_mountlist_for_drive(struct mountlist_itself *mountlist, 2635 char *drive_name, 2636 struct mountlist_reference *drivemntlist) 2637 { 2445 2638 int partno; 2446 2639 char *tmp_drive_name, *c; … … 2450 2643 assert(drivemntlist != NULL); 2451 2644 2452 log_msg (1, "Creating list of partitions for drive %s",drive_name); 2453 2454 tmp_drive_name = strdup (drive_name); 2455 if (!tmp_drive_name) fatal_error ("Out of memory"); 2456 2645 log_msg(1, "Creating list of partitions for drive %s", drive_name); 2646 2647 tmp_drive_name = strdup(drive_name); 2648 if (!tmp_drive_name) 2649 fatal_error("Out of memory"); 2650 2457 2651 /* devfs devices? */ 2458 c = strrchr 2459 if (c && strncmp 2460 2461 strcpy(c + 1, "part");2462 } 2463 drivemntlist->entries =0;2652 c = strrchr(tmp_drive_name, '/'); 2653 if (c && strncmp(c, "/disc", 5) == 0) { 2654 /* yup its devfs, change the "disc" to "part" so the existing code works */ 2655 strcpy(c + 1, "part"); 2656 } 2657 drivemntlist->entries = 0; 2464 2658 for (partno = 0; partno < mountlist->entries; partno++) { 2465 if (strncmp (mountlist->el[partno].device, tmp_drive_name, strlen(tmp_drive_name)) == 0) { 2466 drivemntlist->el[drivemntlist->entries] = &mountlist->el[partno]; 2659 if (strncmp 2660 (mountlist->el[partno].device, tmp_drive_name, 2661 strlen(tmp_drive_name)) == 0) { 2662 drivemntlist->el[drivemntlist->entries] = 2663 &mountlist->el[partno]; 2467 2664 drivemntlist->entries++; 2468 2665 } 2469 2666 } 2470 2667 if (tmp_drive_name) 2471 free(tmp_drive_name);2668 free(tmp_drive_name); 2472 2669 } 2473 2670 -
trunk/mondo/mondo/mondorestore/mondo-restore-EXT.h
r30 r59 6 6 7 7 extern bool g_sigpipe_caught; 8 extern bool g_ISO_restore_mode; 8 extern bool g_ISO_restore_mode; /* are we in Iso Mode? */ 9 9 extern bool g_I_have_just_nuked; 10 10 extern char *g_tmpfs_mountpt; … … 13 13 14 14 extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; 15 extern char 16 extern char 17 extern char 18 extern char 19 extern char *g_filelist_imagedevs;20 extern char *g_filelist_restthese;21 extern char 22 extern char *g_imagedevs_restthese;23 extern char 24 extern char 25 extern char 15 extern char *g_biggielist_txt; 16 extern char *g_filelist_full; 17 extern char *g_biggielist_pot; 18 extern char *g_filelist_potential; 19 extern char *g_filelist_imagedevs; 20 extern char *g_filelist_restthese; 21 extern char *g_biggielist_restthese; 22 extern char *g_imagedevs_restthese; 23 extern char *g_mondo_cfg_file; 24 extern char *g_mountlist_fname; 25 extern char *g_mondo_home; 26 26 27 27 28 extern void ask_about_these_imagedevs(char*,char*); 29 extern int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself*); 30 extern void sort_mountlist_by_device(struct mountlist_itself*); 31 extern void find_pathname_of_executable_preferably_in_RESTORING(char *, char*, char*); 32 extern int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 33 extern int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 34 extern int compare_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 28 extern void ask_about_these_imagedevs(char *, char *); 29 extern int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *, 30 struct raidlist_itself *); 31 extern void sort_mountlist_by_device(struct mountlist_itself *); 32 extern void find_pathname_of_executable_preferably_in_RESTORING(char *, 33 char *, 34 char *); 35 extern int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *, 36 struct raidlist_itself *); 37 extern int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *, 38 struct raidlist_itself *); 39 extern int compare_mode(struct s_bkpinfo *, struct mountlist_itself *, 40 struct raidlist_itself *); 35 41 extern int iso_mode(struct s_bkpinfo *bkpinfo, 36 struct mountlist_itself *mountlist, 37 struct raidlist_itself *raidlist, 38 bool nuke_me_please); 39 extern int load_mountlist(struct mountlist_itself*,char*); 40 extern int load_raidtab_into_raidlist(struct raidlist_itself*,char*); 41 extern int restore_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 42 extern int save_raidlist_to_raidtab(struct raidlist_itself*,char*); 43 extern void process_raidtab_line(FILE*, struct raid_device_record *, char*, char*); 44 extern int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, struct s_node*); 45 extern int restore_a_biggiefile_from_stream(struct s_bkpinfo*, char*, long , char*, long long, struct s_node*); 46 extern int restore_a_tarball_from_CD(char *, int, struct s_node*); 47 extern int restore_a_tarball_from_stream(struct s_bkpinfo*, char *, int, struct s_node*, long long); 48 extern int restore_all_biggiefiles_from_CD(struct s_bkpinfo*, struct s_node*); 49 extern int restore_all_biggiefiles_from_stream(struct s_bkpinfo*, struct s_node*); 50 extern int restore_all_tarballs_from_CD(struct s_bkpinfo*, struct s_node*); 51 extern int restore_all_tarballs_from_stream(struct s_bkpinfo*, struct s_node*); 52 extern int restore_everything(struct s_bkpinfo*, struct s_node*); 53 extern int restore_live_from_monitas_server(struct s_bkpinfo *, char*, char*, char*); 54 extern int restore_to_live_filesystem(struct s_bkpinfo*); 55 extern void swap_mountlist_entries(struct mountlist_itself*,int,int); 56 extern void sort_mountlist_by_mountpoint(struct mountlist_itself*,bool); 57 extern void sort_mountlist_by_device(struct mountlist_itself*); 42 struct mountlist_itself *mountlist, 43 struct raidlist_itself *raidlist, bool nuke_me_please); 44 extern int load_mountlist(struct mountlist_itself *, char *); 45 extern int load_raidtab_into_raidlist(struct raidlist_itself *, char *); 46 extern int restore_mode(struct s_bkpinfo *, struct mountlist_itself *, 47 struct raidlist_itself *); 48 extern int save_raidlist_to_raidtab(struct raidlist_itself *, char *); 49 extern void process_raidtab_line(FILE *, struct raid_device_record *, 50 char *, char *); 51 extern int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, 52 struct s_node *); 53 extern int restore_a_biggiefile_from_stream(struct s_bkpinfo *, char *, 54 long, char *, long long, 55 struct s_node *); 56 extern int restore_a_tarball_from_CD(char *, int, struct s_node *); 57 extern int restore_a_tarball_from_stream(struct s_bkpinfo *, char *, int, 58 struct s_node *, long long); 59 extern int restore_all_biggiefiles_from_CD(struct s_bkpinfo *, 60 struct s_node *); 61 extern int restore_all_biggiefiles_from_stream(struct s_bkpinfo *, 62 struct s_node *); 63 extern int restore_all_tarballs_from_CD(struct s_bkpinfo *, 64 struct s_node *); 65 extern int restore_all_tarballs_from_stream(struct s_bkpinfo *, 66 struct s_node *); 67 extern int restore_everything(struct s_bkpinfo *, struct s_node *); 68 extern int restore_live_from_monitas_server(struct s_bkpinfo *, char *, 69 char *, char *); 70 extern int restore_to_live_filesystem(struct s_bkpinfo *); 71 extern void swap_mountlist_entries(struct mountlist_itself *, int, int); 72 extern void sort_mountlist_by_mountpoint(struct mountlist_itself *, bool); 73 extern void sort_mountlist_by_device(struct mountlist_itself *); 58 74 extern void success_message(void); 59 75 extern void twenty_seconds_til_yikes(void); 60 extern int run_raw_mbr(bool offer_to_hack_scripts, char*bd); 61 extern int save_mountlist_to_disk(struct mountlist_itself*, char*); 62 extern void save_raidrec_to_file(struct raid_device_record *raidrec, FILE*fout); 63 extern int save_raidlist_to_raidtab(struct raidlist_itself *raidlist, char*fname); 64 extern int what_number_cd_is_this(struct s_bkpinfo*); 76 extern int run_raw_mbr(bool offer_to_hack_scripts, char *bd); 77 extern int save_mountlist_to_disk(struct mountlist_itself *, char *); 78 extern void save_raidrec_to_file(struct raid_device_record *raidrec, 79 FILE * fout); 80 extern int save_raidlist_to_raidtab(struct raidlist_itself *raidlist, 81 char *fname); 82 extern int what_number_cd_is_this(struct s_bkpinfo *); 65 83 66 84 #ifdef __FreeBSD__ -
trunk/mondo/mondo/mondorestore/mondo-restore.c
r30 r59 5 5 copyright : (C) 2000 by Hugo Rabson 6 6 email : Hugo Rabson <hugorabson@msn.com> 7 cvsid : $Id : mondo-restore.c,v 1.42 2004/06/21 20:20:37 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 407 407 408 408 409 //static char cvsid[] = "$Id : mondo-restore.c,v 1.42 2004/06/21 20:20:37 hugo Exp$";409 //static char cvsid[] = "$Id$"; 410 410 411 411 /************************************************************************** 412 412 * Globals * 413 413 **************************************************************************/ 414 extern char *g_tmpfs_mountpt; 415 extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; 416 414 extern char *g_tmpfs_mountpt; // declared in libmondo-tools.c 415 extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; // used by finish() to free 416 // up global bkpinfo struct 417 417 extern bool g_text_mode; 418 418 extern FILE *g_fprep; … … 433 433 * Set by the signal handler; cleared after it's handled. 434 434 */ 435 bool g_sigpipe_caught=FALSE;435 bool g_sigpipe_caught = FALSE; 436 436 437 437 /** … … 439 439 * If FALSE, then we're restoring from some kind of real media (tape, CD, etc.) 440 440 */ 441 bool g_ISO_restore_mode = FALSE;/* are we in Iso Mode? */441 bool g_ISO_restore_mode = FALSE; /* are we in Iso Mode? */ 442 442 443 443 /** 444 444 * If TRUE, then we have had a successful "nuke" restore. 445 445 */ 446 bool 446 bool g_I_have_just_nuked = FALSE; 447 447 448 448 /** 449 449 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode. 450 450 */ 451 char 451 char *g_isodir_device; 452 452 453 453 /** 454 454 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode. 455 455 */ 456 char 456 char *g_isodir_format; 457 457 458 458 /** 459 459 * The location of 'biggielist.txt', containing the biggiefiles on the current archive set. 460 460 */ 461 char 461 char *g_biggielist_txt; 462 462 463 463 /** … … 465 465 * the current archive set. 466 466 */ 467 char 467 char *g_filelist_full; 468 468 469 469 /** … … 471 471 * as images, not as individual files. 472 472 */ 473 char 473 char *g_filelist_imagedevs; 474 474 475 475 /** … … 477 477 * @see g_filelist_imagedevs 478 478 */ 479 char 479 char *g_imagedevs_restthese; 480 480 481 481 /** … … 483 483 * information for this backup. 484 484 */ 485 char 485 char *g_mondo_cfg_file; 486 486 487 487 /** … … 489 489 * user's partitions and hard drives. 490 490 */ 491 char 491 char *g_mountlist_fname; 492 492 493 493 /** … … 495 495 * to avoid link errors. 496 496 */ 497 char 497 char *g_mondo_home; 498 498 499 499 /* @} - end of "Restore-Time Globals" in globalGroup */ … … 501 501 502 502 503 extern int copy_from_src_to_dest(FILE*f_orig, FILE*f_archived, char direction); 503 extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived, 504 char direction); 504 505 505 506 … … 525 526 * @ingroup restoreGuiGroup 526 527 */ 527 int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo, struct mountlist_itself *mountlist, struct raidlist_itself *raidlist) 528 int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo, 529 struct mountlist_itself *mountlist, 530 struct raidlist_itself *raidlist) 528 531 { 529 int retval=0, res=0;530 531 532 533 assert(bkpinfo!=NULL);534 assert(mountlist!=NULL);535 assert(raidlist!=NULL);536 if ( !bkpinfo->disaster_recovery ) 537 { 538 strcpy( g_mountlist_fname, "/tmp/mountlist.txt");539 log_msg(2, "I guess you're testing edit_mountlist()" ); 540 } 541 if (!does_file_exist(g_mountlist_fname)) 542 { 543 log_to_screen(g_mountlist_fname);544 log_to_screen("does not exist"); 545 return(1); 546 } 547 548 retval = load_mountlist( mountlist, g_mountlist_fname ); 549 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 550 if ( retval ) { log_to_screen( "Warning - load_raidtab_into_raidlist returned an error" ); } 551 res = edit_mountlist( g_mountlist_fname, mountlist, raidlist ); 552 if ( res ) 553 {554 return( 1 );555 } 556 557 save_mountlist_to_disk( mountlist, g_mountlist_fname);558 save_raidlist_to_raidtab( raidlist, RAIDTAB_FNAME);559 560 561 562 return( retval);563 532 int retval = 0, res = 0; 533 534 log_msg(2, "let_user_edit_the_mountlist() --- starting"); 535 536 assert(bkpinfo != NULL); 537 assert(mountlist != NULL); 538 assert(raidlist != NULL); 539 if (!bkpinfo->disaster_recovery) { 540 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 541 log_msg(2, "I guess you're testing edit_mountlist()"); 542 } 543 if (!does_file_exist(g_mountlist_fname)) { 544 log_to_screen(g_mountlist_fname); 545 log_to_screen("does not exist"); 546 return (1); 547 } 548 549 retval = load_mountlist(mountlist, g_mountlist_fname); 550 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 551 if (retval) { 552 log_to_screen 553 ("Warning - load_raidtab_into_raidlist returned an error"); 554 } 555 res = edit_mountlist(g_mountlist_fname, mountlist, raidlist); 556 if (res) { 557 return (1); 558 } 559 560 save_mountlist_to_disk(mountlist, g_mountlist_fname); 561 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME); 562 563 log_to_screen("I have finished editing the mountlist for you."); 564 565 return (retval); 566 } 564 567 565 568 … … 573 576 * @ingroup restoreUtilityGroup 574 577 */ 575 bool 576 partition_table_contains_Compaq_diagnostic_partition(struct mountlist_itself *mountlist) 578 bool 579 partition_table_contains_Compaq_diagnostic_partition(struct 580 mountlist_itself * 581 mountlist) 577 582 { 578 int i; 579 580 assert(mountlist!=NULL); 581 582 for( i = 0; i < mountlist->entries; i++ ) 583 { 584 if ( strstr( mountlist->el[i].format, "ompaq" ) ) 585 { 586 log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)", 587 i, 588 mountlist->el[i].device, 589 mountlist->el[i].format ); 590 591 return( TRUE ); 592 } 593 } 594 return( FALSE ); 583 int i; 584 585 assert(mountlist != NULL); 586 587 for (i = 0; i < mountlist->entries; i++) { 588 if (strstr(mountlist->el[i].format, "ompaq")) { 589 log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)", 590 i, mountlist->el[i].device, mountlist->el[i].format); 591 592 return (TRUE); 593 } 594 } 595 return (FALSE); 595 596 } 597 596 598 /************************************************************************** 597 599 *END_PARTITION_TABLE_CONTAINS_COMPAQ_DIAGNOSTIC_PARTITION * … … 604 606 * @ingroup restoreUtilityGroup 605 607 */ 606 void 607 offer_to_abort_because_Compaq_Proliants_suck(void) 608 void offer_to_abort_because_Compaq_Proliants_suck(void) 608 609 { 609 popup_and_OK( COMPAQ_PROLIANTS_SUCK ); 610 if ( ask_me_yes_or_no("Would you like to reboot and use your Compaq CD to prep your hard drive?") ) 611 { 612 fatal_error( "Aborting. Please reboot and prep your hard drive with your Compaq CD." ); 613 } 610 popup_and_OK(COMPAQ_PROLIANTS_SUCK); 611 if (ask_me_yes_or_no 612 ("Would you like to reboot and use your Compaq CD to prep your hard drive?")) 613 { 614 fatal_error 615 ("Aborting. Please reboot and prep your hard drive with your Compaq CD."); 616 } 614 617 } 618 615 619 /************************************************************************** 616 620 *END_OFFER_TO_ABORT_BECAUSE_COMPAQ_PROLIANTS_SUCK * … … 627 631 * @ingroup restoreGroup 628 632 */ 629 int 630 catchall_mode( struct s_bkpinfo *bkpinfo,631 struct mountlist_itself *mountlist,632 struct raidlist_itself*raidlist)633 int 634 catchall_mode(struct s_bkpinfo *bkpinfo, 635 struct mountlist_itself *mountlist, 636 struct raidlist_itself *raidlist) 633 637 { 634 char c, *tmp; 635 int retval = 0; 636 637 iamhere("inside catchall"); 638 assert(bkpinfo!=NULL); 639 assert(mountlist!=NULL); 640 assert(raidlist!=NULL); 641 malloc_string(tmp); 642 iamhere("pre wrm"); 643 c = which_restore_mode(); 644 iamhere("post wrm"); 645 if ( c == 'I' || c == 'N' || c == 'C') 646 { 647 interactively_obtain_media_parameters_from_user( bkpinfo, FALSE); 648 } 649 else 650 { 651 popup_and_OK( "No restoring or comparing will take place today." ); 652 if ( is_this_device_mounted( "/mnt/cdrom" ) ) 653 { 654 run_program_and_log_output( "umount /mnt/cdrom", FALSE); 655 } 656 if ( g_ISO_restore_mode ) 657 { 658 sprintf(tmp, "umount %s", bkpinfo->isodir); 659 run_program_and_log_output( tmp, FALSE); 660 } 661 paranoid_MR_finish( 0 ); 662 } 663 664 iamhere("post int"); 665 666 if (bkpinfo->backup_media_type == iso) 667 { 668 if (iso_fiddly_bits(bkpinfo, (c=='N')?TRUE:FALSE)) 669 { log_msg(2, "catchall_mode --- iso_fiddly_bits returned w/ error"); return(1); } 670 else 671 { log_msg(2, "catchall_mode --- iso_fiddly_bits ok"); } 672 } 673 674 if (c == 'I' ) 675 { 676 log_msg(2, "IM selected" ); 677 retval += interactive_mode( bkpinfo,mountlist,raidlist ); 678 } 679 else if 680 ( c == 'N' ) 681 { 682 log_msg(2, "NM selected"); 683 retval += nuke_mode( bkpinfo, mountlist, raidlist ); } 684 else if 685 ( c == 'C' ) 686 { 687 log_msg(2, "CM selected" ); 688 retval += compare_mode( bkpinfo, mountlist, raidlist); 689 } 690 paranoid_free(tmp); 691 return( retval ); 638 char c, *tmp; 639 int retval = 0; 640 641 iamhere("inside catchall"); 642 assert(bkpinfo != NULL); 643 assert(mountlist != NULL); 644 assert(raidlist != NULL); 645 malloc_string(tmp); 646 iamhere("pre wrm"); 647 c = which_restore_mode(); 648 iamhere("post wrm"); 649 if (c == 'I' || c == 'N' || c == 'C') { 650 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 651 } else { 652 popup_and_OK("No restoring or comparing will take place today."); 653 if (is_this_device_mounted("/mnt/cdrom")) { 654 run_program_and_log_output("umount /mnt/cdrom", FALSE); 655 } 656 if (g_ISO_restore_mode) { 657 sprintf(tmp, "umount %s", bkpinfo->isodir); 658 run_program_and_log_output(tmp, FALSE); 659 } 660 paranoid_MR_finish(0); 661 } 662 663 iamhere("post int"); 664 665 if (bkpinfo->backup_media_type == iso) { 666 if (iso_fiddly_bits(bkpinfo, (c == 'N') ? TRUE : FALSE)) { 667 log_msg(2, 668 "catchall_mode --- iso_fiddly_bits returned w/ error"); 669 return (1); 670 } else { 671 log_msg(2, "catchall_mode --- iso_fiddly_bits ok"); 672 } 673 } 674 675 if (c == 'I') { 676 log_msg(2, "IM selected"); 677 retval += interactive_mode(bkpinfo, mountlist, raidlist); 678 } else if (c == 'N') { 679 log_msg(2, "NM selected"); 680 retval += nuke_mode(bkpinfo, mountlist, raidlist); 681 } else if (c == 'C') { 682 log_msg(2, "CM selected"); 683 retval += compare_mode(bkpinfo, mountlist, raidlist); 684 } 685 paranoid_free(tmp); 686 return (retval); 692 687 } 688 693 689 /************************************************************************** 694 690 *END_CATCHALL_MODE * … … 709 705 */ 710 706 void 711 find_pathname_of_executable_preferably_in_RESTORING( char *out_path, char *fname, char*restg ) 707 find_pathname_of_executable_preferably_in_RESTORING(char *out_path, 708 char *fname, 709 char *restg) 712 710 { 713 assert(out_path!=NULL); 714 assert_string_is_neither_NULL_nor_zerolength(fname); 715 716 sprintf( out_path, "%s/sbin/%s", restg, fname ); 717 if ( does_file_exist(out_path) ) 718 { 719 sprintf( out_path, "%s/usr/sbin/%s", restg, fname ); 720 if ( does_file_exist( out_path ) ) 721 { 722 sprintf( out_path, "%s/bin/%s", restg, fname ); 723 if ( does_file_exist( out_path ) ) 724 { 725 sprintf( out_path, "%s/usr/bin/%s", restg, fname ); 726 if ( does_file_exist( out_path ) ) 727 { 728 strcpy( out_path, fname ); 729 } 730 } 731 } 732 } 711 assert(out_path != NULL); 712 assert_string_is_neither_NULL_nor_zerolength(fname); 713 714 sprintf(out_path, "%s/sbin/%s", restg, fname); 715 if (does_file_exist(out_path)) { 716 sprintf(out_path, "%s/usr/sbin/%s", restg, fname); 717 if (does_file_exist(out_path)) { 718 sprintf(out_path, "%s/bin/%s", restg, fname); 719 if (does_file_exist(out_path)) { 720 sprintf(out_path, "%s/usr/bin/%s", restg, fname); 721 if (does_file_exist(out_path)) { 722 strcpy(out_path, fname); 723 } 724 } 725 } 726 } 733 727 } 734 728 … … 753 747 * @return 0 for success, or the number of errors encountered. 754 748 */ 755 int 756 interactive_mode( struct s_bkpinfo *bkpinfo,757 struct mountlist_itself *mountlist,758 749 int 750 interactive_mode(struct s_bkpinfo *bkpinfo, 751 struct mountlist_itself *mountlist, 752 struct raidlist_itself *raidlist) 759 753 { 760 761 762 763 764 765 766 754 int retval = 0; 755 int res; 756 int ptn_errs = 0; 757 int fmt_errs = 0; 758 759 bool done; 760 bool restore_all; 767 761 768 762 /** needs malloc **********/ 769 char *tmp; 770 char *fstab_fname; 771 char *old_restpath; 772 773 struct s_node *filelist; 774 775 /* try to partition and format */ 776 777 log_msg(2,"interactive_mode --- starting (great, assertions OK)"); 778 779 malloc_string(tmp); 780 malloc_string(fstab_fname); 781 malloc_string(old_restpath); 782 assert(bkpinfo!=NULL); 783 assert(mountlist!=NULL); 784 assert(raidlist!=NULL); 785 786 log_msg(2,"interactive_mode --- assertions OK"); 787 788 if (g_text_mode) 789 { 790 if (!ask_me_yes_or_no("Interactive Mode + textonly = experimental! Proceed anyway?")) 791 { fatal_error("Wise move."); } 792 } 793 794 iamhere("About to load config file"); 795 get_cfg_file_from_archive_or_bust(bkpinfo); 796 read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo ); 797 iamhere("Done loading config file; resizing ML"); 763 char *tmp; 764 char *fstab_fname; 765 char *old_restpath; 766 767 struct s_node *filelist; 768 769 /* try to partition and format */ 770 771 log_msg(2, "interactive_mode --- starting (great, assertions OK)"); 772 773 malloc_string(tmp); 774 malloc_string(fstab_fname); 775 malloc_string(old_restpath); 776 assert(bkpinfo != NULL); 777 assert(mountlist != NULL); 778 assert(raidlist != NULL); 779 780 log_msg(2, "interactive_mode --- assertions OK"); 781 782 if (g_text_mode) { 783 if (!ask_me_yes_or_no 784 ("Interactive Mode + textonly = experimental! Proceed anyway?")) 785 { 786 fatal_error("Wise move."); 787 } 788 } 789 790 iamhere("About to load config file"); 791 get_cfg_file_from_archive_or_bust(bkpinfo); 792 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 793 iamhere("Done loading config file; resizing ML"); 798 794 #ifdef __FreeBSD__ 799 if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize")) 795 if (strstr 796 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"), 797 "noresize")) 800 798 #else 801 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize")) 799 if (strstr 800 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 801 "noresize")) 802 802 #endif 803 { log_msg(1,"Not resizing mountlist."); } 804 else 805 { resize_mountlist_proportionately_to_suit_new_drives(mountlist); } 806 for( done = FALSE; !done; ) 807 { 808 iamhere("About to edit mountlist"); 809 if (g_text_mode) 810 { 811 save_mountlist_to_disk (mountlist, g_mountlist_fname); 812 sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname); 813 res = system(tmp); 814 load_mountlist (mountlist, g_mountlist_fname); 815 } 816 else 817 { 818 res = edit_mountlist( g_mountlist_fname, mountlist, raidlist ); 819 } 820 iamhere("Finished editing mountlist"); 821 if ( res ) 822 { 823 paranoid_MR_finish( 1 ); 824 } 825 log_msg(2, "Proceeding..." ); 826 save_mountlist_to_disk( mountlist, g_mountlist_fname ); 827 save_raidlist_to_raidtab( raidlist, RAIDTAB_FNAME ); 828 mvaddstr_and_log_it( 1, 30, "Restoring Interactively" ); 829 if ( bkpinfo->differential ) 830 { 831 log_to_screen( "Because this is a differential backup, disk" ); 832 log_to_screen(" partitioning and formatting will not take place." ); 833 done=TRUE; 834 } 835 else 836 { 837 if ( ask_me_yes_or_no( "Do you want to erase and partition your hard drives?" ) ) 838 { 839 if ( partition_table_contains_Compaq_diagnostic_partition( mountlist ) ) 840 { offer_to_abort_because_Compaq_Proliants_suck(); done=TRUE; } 841 else 842 { 843 twenty_seconds_til_yikes(); 844 g_fprep = fopen("/tmp/prep.sh", "w"); 845 ptn_errs = partition_everything( mountlist ); 846 if (ptn_errs) 847 { 848 log_to_screen("Warning. Errors occurred during disk partitioning."); 849 } 850 851 fmt_errs = format_everything( mountlist, FALSE ); 852 if (!fmt_errs) 853 { 854 log_to_screen("Errors during disk partitioning were handled OK."); 855 log_to_screen("Partitions were formatted OK despite those errors."); 856 ptn_errs = 0; 857 } 858 if ( !ptn_errs && !fmt_errs) 859 { 860 done = TRUE; 861 } 862 } 863 paranoid_fclose(g_fprep); 864 } 865 else 866 { 867 mvaddstr_and_log_it( g_currentY++, 0, "User opted not to partition the devices" ); 868 if ( ask_me_yes_or_no( "Do you want to format your hard drives?" ) ) 869 { 870 fmt_errs = format_everything( mountlist, TRUE ); 871 if (!fmt_errs) 872 { 873 done = TRUE; 874 } 875 } 876 else 877 { 878 ptn_errs = fmt_errs = 0; 879 done = TRUE; 880 } 881 } 882 if (fmt_errs) 883 { 884 mvaddstr_and_log_it( g_currentY++, 885 0, 886 "Errors occurred. Please repartition and format drives manually."); 887 done = FALSE; 888 } 889 if ( ptn_errs & !fmt_errs ) 890 { 891 mvaddstr_and_log_it( g_currentY++, 892 0, 893 "Errors occurred during partitioning. Formatting, however, went OK."); 894 done = TRUE; 895 } 896 if ( !done ) 897 { 898 if ( !ask_me_yes_or_no( "Re-edit the mountlist?" ) ) 899 { 900 retval++; 901 goto end_of_func; 902 } 903 } 904 } 905 } 906 907 /* mount */ 908 if ( mount_all_devices( mountlist, TRUE ) ) 909 { 910 unmount_all_devices( mountlist ); 911 retval++; 912 goto end_of_func; 913 } 914 /* restore */ 915 if ( ( restore_all = ask_me_yes_or_no( "Do you want me to restore all of your data?" ) ) ) 916 { 917 log_msg(1, "Restoring all data"); 918 retval += restore_everything( bkpinfo, NULL ); 919 } 920 else if ( ( restore_all = ask_me_yes_or_no( "Do you want me to restore _some_ of your data?") ) ) 921 { 922 strcpy( old_restpath, bkpinfo->restore_path ); 923 for( done = FALSE; !done; ) 924 { 925 unlink("/tmp/filelist.full"); 926 filelist = process_filelist_and_biggielist( bkpinfo ); 927 /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these; 928 the former is a list of regular files; the latter, biggiefiles and imagedevs. 929 */ 930 if ( filelist ) 931 { 932 gotos_suck: 933 strcpy( tmp, old_restpath ); 803 { 804 log_msg(1, "Not resizing mountlist."); 805 } else { 806 resize_mountlist_proportionately_to_suit_new_drives(mountlist); 807 } 808 for (done = FALSE; !done;) { 809 iamhere("About to edit mountlist"); 810 if (g_text_mode) { 811 save_mountlist_to_disk(mountlist, g_mountlist_fname); 812 sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname); 813 res = system(tmp); 814 load_mountlist(mountlist, g_mountlist_fname); 815 } else { 816 res = edit_mountlist(g_mountlist_fname, mountlist, raidlist); 817 } 818 iamhere("Finished editing mountlist"); 819 if (res) { 820 paranoid_MR_finish(1); 821 } 822 log_msg(2, "Proceeding..."); 823 save_mountlist_to_disk(mountlist, g_mountlist_fname); 824 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME); 825 mvaddstr_and_log_it(1, 30, "Restoring Interactively"); 826 if (bkpinfo->differential) { 827 log_to_screen("Because this is a differential backup, disk"); 828 log_to_screen 829 (" partitioning and formatting will not take place."); 830 done = TRUE; 831 } else { 832 if (ask_me_yes_or_no 833 ("Do you want to erase and partition your hard drives?")) { 834 if (partition_table_contains_Compaq_diagnostic_partition 835 (mountlist)) { 836 offer_to_abort_because_Compaq_Proliants_suck(); 837 done = TRUE; 838 } else { 839 twenty_seconds_til_yikes(); 840 g_fprep = fopen("/tmp/prep.sh", "w"); 841 ptn_errs = partition_everything(mountlist); 842 if (ptn_errs) { 843 log_to_screen 844 ("Warning. Errors occurred during disk partitioning."); 845 } 846 847 fmt_errs = format_everything(mountlist, FALSE); 848 if (!fmt_errs) { 849 log_to_screen 850 ("Errors during disk partitioning were handled OK."); 851 log_to_screen 852 ("Partitions were formatted OK despite those errors."); 853 ptn_errs = 0; 854 } 855 if (!ptn_errs && !fmt_errs) { 856 done = TRUE; 857 } 858 } 859 paranoid_fclose(g_fprep); 860 } else { 861 mvaddstr_and_log_it(g_currentY++, 0, 862 "User opted not to partition the devices"); 863 if (ask_me_yes_or_no 864 ("Do you want to format your hard drives?")) { 865 fmt_errs = format_everything(mountlist, TRUE); 866 if (!fmt_errs) { 867 done = TRUE; 868 } 869 } else { 870 ptn_errs = fmt_errs = 0; 871 done = TRUE; 872 } 873 } 874 if (fmt_errs) { 875 mvaddstr_and_log_it(g_currentY++, 876 0, 877 "Errors occurred. Please repartition and format drives manually."); 878 done = FALSE; 879 } 880 if (ptn_errs & !fmt_errs) { 881 mvaddstr_and_log_it(g_currentY++, 882 0, 883 "Errors occurred during partitioning. Formatting, however, went OK."); 884 done = TRUE; 885 } 886 if (!done) { 887 if (!ask_me_yes_or_no("Re-edit the mountlist?")) { 888 retval++; 889 goto end_of_func; 890 } 891 } 892 } 893 } 894 895 /* mount */ 896 if (mount_all_devices(mountlist, TRUE)) { 897 unmount_all_devices(mountlist); 898 retval++; 899 goto end_of_func; 900 } 901 /* restore */ 902 if ((restore_all = 903 ask_me_yes_or_no("Do you want me to restore all of your data?"))) 904 { 905 log_msg(1, "Restoring all data"); 906 retval += restore_everything(bkpinfo, NULL); 907 } else 908 if ((restore_all = 909 ask_me_yes_or_no 910 ("Do you want me to restore _some_ of your data?"))) { 911 strcpy(old_restpath, bkpinfo->restore_path); 912 for (done = FALSE; !done;) { 913 unlink("/tmp/filelist.full"); 914 filelist = process_filelist_and_biggielist(bkpinfo); 915 /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these; 916 the former is a list of regular files; the latter, biggiefiles and imagedevs. 917 */ 918 if (filelist) { 919 gotos_suck: 920 strcpy(tmp, old_restpath); 934 921 // (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING); 935 if ( popup_and_get_string( "Restore path", "Restore files to where?", tmp, MAX_STR_LEN/4 ) ) 936 { 937 if ( !strcmp( tmp, "/" ) ) 938 { 939 if ( !ask_me_yes_or_no( "Are you sure?" ) ) 940 { 941 goto gotos_suck; 942 } 943 tmp[0] = '\0'; // so we restore to [blank]/file/name :) 944 } 945 strcpy( bkpinfo->restore_path, tmp ); 946 log_msg(1, "Restoring subset"); 947 retval += restore_everything( bkpinfo, filelist ); 948 free_filelist( filelist ); 949 } 950 else 951 { 952 strcpy( bkpinfo->restore_path, old_restpath ); 953 free_filelist( filelist ); 954 } 955 if ( !ask_me_yes_or_no( "Restore another subset of your backup?" ) ) 956 { 957 done = TRUE; 958 } 959 } 960 else 961 { 962 done = TRUE; 963 } 964 } 965 strcpy( old_restpath, bkpinfo->restore_path ); 966 } 967 else 968 { 969 mvaddstr_and_log_it( g_currentY++, 970 0, 971 "User opted not to restore any data. "); 972 } 973 if ( retval ) 974 { 975 mvaddstr_and_log_it( g_currentY++, 976 0, 977 "Errors occurred during the restore phase. "); 978 } 979 980 if (ask_me_yes_or_no( "Initialize the boot loader?" ) ) 981 { 982 run_boot_loader( TRUE ); 983 } 984 else 985 { 986 mvaddstr_and_log_it( g_currentY++, 987 0, 988 "User opted not to initialize the boot loader."); 989 } 922 if (popup_and_get_string 923 ("Restore path", "Restore files to where?", tmp, 924 MAX_STR_LEN / 4)) { 925 if (!strcmp(tmp, "/")) { 926 if (!ask_me_yes_or_no("Are you sure?")) { 927 goto gotos_suck; 928 } 929 tmp[0] = '\0'; // so we restore to [blank]/file/name :) 930 } 931 strcpy(bkpinfo->restore_path, tmp); 932 log_msg(1, "Restoring subset"); 933 retval += restore_everything(bkpinfo, filelist); 934 free_filelist(filelist); 935 } else { 936 strcpy(bkpinfo->restore_path, old_restpath); 937 free_filelist(filelist); 938 } 939 if (!ask_me_yes_or_no 940 ("Restore another subset of your backup?")) { 941 done = TRUE; 942 } 943 } else { 944 done = TRUE; 945 } 946 } 947 strcpy(old_restpath, bkpinfo->restore_path); 948 } else { 949 mvaddstr_and_log_it(g_currentY++, 950 0, 951 "User opted not to restore any data. "); 952 } 953 if (retval) { 954 mvaddstr_and_log_it(g_currentY++, 955 0, 956 "Errors occurred during the restore phase. "); 957 } 958 959 if (ask_me_yes_or_no("Initialize the boot loader?")) { 960 run_boot_loader(TRUE); 961 } else { 962 mvaddstr_and_log_it(g_currentY++, 963 0, 964 "User opted not to initialize the boot loader."); 965 } 990 966 991 967 // run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1); 992 protect_against_braindead_sysadmins(); 993 // modify_rclocal_one_time( MNT_RESTORING "/etc" ); 994 retval += unmount_all_devices( mountlist ); 995 /* if (restore_some || restore_all || */ 996 if ( ask_me_yes_or_no( "Label your ext2 and ext3 partitions if necessary?" ) ) 997 { 998 mvaddstr_and_log_it( g_currentY, 999 0, 1000 "Using e2label to label your ext2,3 partitions" ); 1001 if ( does_file_exist( "/tmp/fstab.new" ) ) 1002 { 1003 strcpy( fstab_fname, "/tmp/fstab.new"); 1004 } 1005 else 1006 { 1007 strcpy( fstab_fname, "/tmp/fstab"); 1008 } 1009 sprintf( tmp, 1010 "label-partitions-as-necessary %s < %s >> %s 2>> %s", g_mountlist_fname, 1011 fstab_fname, MONDO_LOGFILE, MONDO_LOGFILE); 1012 res=system( tmp ); 1013 if ( res ) 1014 { 1015 log_to_screen("label-partitions-as-necessary returned an error"); 1016 mvaddstr_and_log_it( g_currentY++, 74, "Failed."); 1017 } 1018 else 1019 { 1020 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1021 } 1022 retval += res; 1023 } 1024 1025 iamhere("About to leave interactive_mode()"); 1026 if ( retval ) 1027 { 1028 mvaddstr_and_log_it(g_currentY++, 1029 0, 1030 "Warning - errors occurred during the restore phase."); 1031 } 1032 end_of_func: 1033 paranoid_free(tmp); 1034 paranoid_free(fstab_fname); 1035 paranoid_free(old_restpath); 1036 iamhere("Leaving interactive_mode()"); 1037 return( retval ); 968 protect_against_braindead_sysadmins(); 969 // modify_rclocal_one_time( MNT_RESTORING "/etc" ); 970 retval += unmount_all_devices(mountlist); 971 /* if (restore_some || restore_all || */ 972 if (ask_me_yes_or_no 973 ("Label your ext2 and ext3 partitions if necessary?")) { 974 mvaddstr_and_log_it(g_currentY, 0, 975 "Using e2label to label your ext2,3 partitions"); 976 if (does_file_exist("/tmp/fstab.new")) { 977 strcpy(fstab_fname, "/tmp/fstab.new"); 978 } else { 979 strcpy(fstab_fname, "/tmp/fstab"); 980 } 981 sprintf(tmp, 982 "label-partitions-as-necessary %s < %s >> %s 2>> %s", 983 g_mountlist_fname, fstab_fname, MONDO_LOGFILE, 984 MONDO_LOGFILE); 985 res = system(tmp); 986 if (res) { 987 log_to_screen 988 ("label-partitions-as-necessary returned an error"); 989 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 990 } else { 991 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 992 } 993 retval += res; 994 } 995 996 iamhere("About to leave interactive_mode()"); 997 if (retval) { 998 mvaddstr_and_log_it(g_currentY++, 999 0, 1000 "Warning - errors occurred during the restore phase."); 1001 } 1002 end_of_func: 1003 paranoid_free(tmp); 1004 paranoid_free(fstab_fname); 1005 paranoid_free(old_restpath); 1006 iamhere("Leaving interactive_mode()"); 1007 return (retval); 1038 1008 } 1009 1039 1010 /************************************************************************** 1040 1011 *END_INTERACTIVE_MODE * … … 1052 1023 * @return 0 for success, or the number of errors encountered. 1053 1024 */ 1054 int 1055 iso_mode(struct s_bkpinfo *bkpinfo, 1056 struct mountlist_itself *mountlist, 1057 struct raidlist_itself *raidlist, 1058 bool nuke_me_please) 1025 int 1026 iso_mode(struct s_bkpinfo *bkpinfo, 1027 struct mountlist_itself *mountlist, 1028 struct raidlist_itself *raidlist, bool nuke_me_please) 1059 1029 { 1060 char c; 1061 int retval=0; 1062 1063 assert(bkpinfo!=NULL); 1064 assert(mountlist!=NULL); 1065 assert(raidlist!=NULL); 1066 if (iso_fiddly_bits(bkpinfo, nuke_me_please)) 1067 { log_msg(1,"iso_mode --- returning w/ error"); return(1); } 1068 else 1069 { 1070 c=which_restore_mode(); 1071 if (c=='I' || c=='N' || c=='C') 1072 { interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); } 1073 if (c=='I') { retval+=interactive_mode(bkpinfo,mountlist,raidlist); } 1074 else if (c=='N') { retval+=nuke_mode(bkpinfo,mountlist,raidlist); } 1075 else if (c=='C') { retval+=compare_mode(bkpinfo,mountlist,raidlist); } 1076 else 1077 { log_to_screen("OK, I shan't restore/compare any files."); } 1078 } 1079 if (is_this_device_mounted(MNT_CDROM)) { paranoid_system("umount "MNT_CDROM); } 1030 char c; 1031 int retval = 0; 1032 1033 assert(bkpinfo != NULL); 1034 assert(mountlist != NULL); 1035 assert(raidlist != NULL); 1036 if (iso_fiddly_bits(bkpinfo, nuke_me_please)) { 1037 log_msg(1, "iso_mode --- returning w/ error"); 1038 return (1); 1039 } else { 1040 c = which_restore_mode(); 1041 if (c == 'I' || c == 'N' || c == 'C') { 1042 interactively_obtain_media_parameters_from_user(bkpinfo, 1043 FALSE); 1044 } 1045 if (c == 'I') { 1046 retval += interactive_mode(bkpinfo, mountlist, raidlist); 1047 } else if (c == 'N') { 1048 retval += nuke_mode(bkpinfo, mountlist, raidlist); 1049 } else if (c == 'C') { 1050 retval += compare_mode(bkpinfo, mountlist, raidlist); 1051 } else { 1052 log_to_screen("OK, I shan't restore/compare any files."); 1053 } 1054 } 1055 if (is_this_device_mounted(MNT_CDROM)) { 1056 paranoid_system("umount " MNT_CDROM); 1057 } 1080 1058 // if (! already_mounted) 1081 1059 // { 1082 if (system("umount /tmp/isodir 2> /dev/null")) { log_to_screen("WARNING - unable to unmount device where the ISO files are stored."); } 1060 if (system("umount /tmp/isodir 2> /dev/null")) { 1061 log_to_screen 1062 ("WARNING - unable to unmount device where the ISO files are stored."); 1063 } 1083 1064 // } 1084 return( retval);1065 return (retval); 1085 1066 } 1067 1086 1068 /************************************************************************** 1087 1069 *END_ISO_MODE * … … 1103 1085 * @warning <b><i>THIS WILL ERASE ALL EXISTING DATA!</i></b> 1104 1086 */ 1105 int 1106 nuke_mode( struct s_bkpinfo *bkpinfo,1107 1108 struct raidlist_itself *raidlist)1087 int 1088 nuke_mode(struct s_bkpinfo *bkpinfo, 1089 struct mountlist_itself *mountlist, 1090 struct raidlist_itself *raidlist) 1109 1091 { 1110 1111 1112 1092 int retval = 0; 1093 int res = 0; 1094 bool boot_loader_installed = FALSE; 1113 1095 /** malloc **/ 1114 char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN], tmpC[MAX_STR_LEN]; 1115 1116 assert(bkpinfo!=NULL); 1117 assert(mountlist!=NULL); 1118 assert(raidlist!=NULL); 1119 1120 log_msg(2, "nuke_mode --- starting"); 1121 1122 get_cfg_file_from_archive_or_bust(bkpinfo); 1123 load_mountlist( mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist 1096 char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN], 1097 tmpC[MAX_STR_LEN]; 1098 1099 assert(bkpinfo != NULL); 1100 assert(mountlist != NULL); 1101 assert(raidlist != NULL); 1102 1103 log_msg(2, "nuke_mode --- starting"); 1104 1105 get_cfg_file_from_archive_or_bust(bkpinfo); 1106 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist 1124 1107 #ifdef __FreeBSD__ 1125 if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize")) 1108 if (strstr 1109 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"), 1110 "noresize")) 1126 1111 #else 1127 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize")) 1112 if (strstr 1113 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 1114 "noresize")) 1128 1115 #endif 1129 { log_msg(2, "Not resizing mountlist."); }1130 else1131 { resize_mountlist_proportionately_to_suit_new_drives(mountlist); }1132 if (!evaluate_mountlist( mountlist, tmpA, tmpB, tmpC ))1133 {1134 sprintf(tmp, "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?", tmpA, tmpB, tmpC);1135 if (ask_me_yes_or_no(tmp) )1136 1116 { 1137 retval = interactive_mode( bkpinfo, mountlist, raidlist ); 1138 finish(retval); 1139 } 1140 else 1117 log_msg(2, "Not resizing mountlist."); 1118 } else { 1119 resize_mountlist_proportionately_to_suit_new_drives(mountlist); 1120 } 1121 if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) { 1122 sprintf(tmp, 1123 "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?", 1124 tmpA, tmpB, tmpC); 1125 if (ask_me_yes_or_no(tmp)) { 1126 retval = interactive_mode(bkpinfo, mountlist, raidlist); 1127 finish(retval); 1128 } else { 1129 fatal_error("Nuke Mode aborted. "); 1130 } 1131 } 1132 save_mountlist_to_disk(mountlist, g_mountlist_fname); 1133 mvaddstr_and_log_it(1, 30, "Restoring Automatically"); 1134 if (bkpinfo->differential) { 1135 log_to_screen("Because this is a differential backup, disk"); 1136 log_to_screen("partitioning and formatting will not take place."); 1137 res = 0; 1138 } else { 1139 if (partition_table_contains_Compaq_diagnostic_partition 1140 (mountlist)) { 1141 offer_to_abort_because_Compaq_Proliants_suck(); 1142 } else { 1143 twenty_seconds_til_yikes(); 1144 g_fprep = fopen("/tmp/prep.sh", "w"); 1145 #ifdef __FreeBSD__ 1146 if (strstr 1147 (call_program_and_get_last_line_of_output 1148 ("cat /tmp/cmdline"), "nopart")) 1149 #else 1150 if (strstr 1151 (call_program_and_get_last_line_of_output 1152 ("cat /proc/cmdline"), "nopart")) 1153 #endif 1154 { 1155 log_msg(2, 1156 "Not partitioning drives due to 'nopart' option."); 1157 res = 0; 1158 } else { 1159 res = partition_everything(mountlist); 1160 if (res) { 1161 log_to_screen 1162 ("Warning. Errors occurred during partitioning."); 1163 res = 0; 1164 } 1165 } 1166 retval += res; 1167 if (!res) { 1168 log_to_screen("Preparing to format your disk(s)"); 1169 sleep(1); 1170 system("sync"); 1171 log_to_screen("Please wait. This may take a few minutes."); 1172 res += format_everything(mountlist, FALSE); 1173 } 1174 paranoid_fclose(g_fprep); 1175 } 1176 } 1177 retval += res; 1178 if (res) { 1179 mvaddstr_and_log_it(g_currentY++, 1180 0, 1181 "Failed to partition and/or format your hard drives."); 1182 1183 if (ask_me_yes_or_no("Try in interactive mode instead?")) { 1184 retval = interactive_mode(bkpinfo, mountlist, raidlist); 1185 goto after_the_nuke; 1186 } else 1187 if (!ask_me_yes_or_no 1188 ("Would you like to try to proceed anyway?")) { 1189 return (retval); 1190 } 1191 } 1192 retval = mount_all_devices(mountlist, TRUE); 1193 if (retval) { 1194 unmount_all_devices(mountlist); 1195 log_to_screen 1196 ("Unable to mount all partitions. Sorry, I cannot proceed."); 1197 return (retval); 1198 } 1199 iamhere("Restoring everything"); 1200 retval += restore_everything(bkpinfo, NULL); 1201 if (!run_boot_loader(FALSE)) { 1202 log_msg(1, 1203 "Great! Boot loader was installed. No need for msg at end."); 1204 boot_loader_installed = TRUE; 1205 } 1206 protect_against_braindead_sysadmins(); 1207 // run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1); 1208 // modify_rclocal_one_time( MNT_RESTORING "/etc" ); 1209 retval += unmount_all_devices(mountlist); 1210 mvaddstr_and_log_it(g_currentY, 1211 0, 1212 "Using e2label to label your ext2,3 partitions"); 1213 1214 sprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab", 1215 g_mountlist_fname); 1216 res = run_program_and_log_output(tmp, TRUE); 1217 if (res) { 1218 log_to_screen("label-partitions-as-necessary returned an error"); 1219 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1220 } else { 1221 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1222 } 1223 retval += res; 1224 1225 after_the_nuke: 1226 if (retval) { 1227 log_to_screen("Errors occurred during the nuke phase."); 1228 } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE")) // Bruno's thing 1141 1229 { 1142 fatal_error( "Nuke Mode aborted. "); 1143 } 1144 } 1145 save_mountlist_to_disk( mountlist, g_mountlist_fname ); 1146 mvaddstr_and_log_it( 1, 30, "Restoring Automatically" ); 1147 if ( bkpinfo->differential ) 1148 { 1149 log_to_screen( "Because this is a differential backup, disk" ); 1150 log_to_screen( "partitioning and formatting will not take place." ); 1151 res = 0; 1152 } 1153 else 1154 { 1155 if ( partition_table_contains_Compaq_diagnostic_partition( mountlist ) ) 1156 { 1157 offer_to_abort_because_Compaq_Proliants_suck(); 1158 } 1159 else 1160 { 1161 twenty_seconds_til_yikes(); 1162 g_fprep = fopen("/tmp/prep.sh", "w"); 1163 #ifdef __FreeBSD__ 1164 if (strstr (call_program_and_get_last_line_of_output ("cat /tmp/cmdline"), "nopart")) 1230 log_to_screen 1231 ("PC was restored successfully. Thank you for using Mondo Rescue."); 1232 log_to_screen 1233 ("Please visit http://www.mondorescue.org and thank the dev team."); 1234 } else { 1235 #ifdef FREELOADER 1236 success_message(); 1165 1237 #else 1166 if (strstr (call_program_and_get_last_line_of_output ("cat /proc/cmdline"), "nopart"))1238 log_to_screen("PC was restored successfully!"); 1167 1239 #endif 1168 { 1169 log_msg (2, "Not partitioning drives due to 'nopart' option."); 1170 res = 0; 1171 } 1172 else 1173 { 1174 res = partition_everything( mountlist ); 1175 if (res) 1176 { 1177 log_to_screen("Warning. Errors occurred during partitioning."); 1178 res = 0; 1179 } 1180 } 1181 retval += res; 1182 if ( !res ) 1183 { 1184 log_to_screen("Preparing to format your disk(s)"); 1185 sleep(1); 1186 system("sync"); 1187 log_to_screen("Please wait. This may take a few minutes."); 1188 res += format_everything( mountlist, FALSE ); 1189 } 1190 paranoid_fclose(g_fprep); 1191 } 1192 } 1193 retval += res; 1194 if ( res ) 1195 { 1196 mvaddstr_and_log_it( g_currentY++, 1197 0, 1198 "Failed to partition and/or format your hard drives."); 1199 1200 if ( ask_me_yes_or_no( "Try in interactive mode instead?" ) ) 1201 { 1202 retval = interactive_mode( bkpinfo, mountlist, raidlist ); 1203 goto after_the_nuke; 1204 } 1205 else if ( !ask_me_yes_or_no( "Would you like to try to proceed anyway?" ) ) 1206 { 1207 return( retval ); 1208 } 1209 } 1210 retval = mount_all_devices( mountlist, TRUE ); 1211 if ( retval ) 1212 { 1213 unmount_all_devices( mountlist ); 1214 log_to_screen("Unable to mount all partitions. Sorry, I cannot proceed."); 1215 return( retval ); 1216 } 1217 iamhere("Restoring everything"); 1218 retval += restore_everything( bkpinfo, NULL ); 1219 if (!run_boot_loader( FALSE )) 1220 { 1221 log_msg(1, "Great! Boot loader was installed. No need for msg at end."); 1222 boot_loader_installed = TRUE; 1223 } 1224 protect_against_braindead_sysadmins(); 1225 // run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1); 1226 // modify_rclocal_one_time( MNT_RESTORING "/etc" ); 1227 retval += unmount_all_devices( mountlist ); 1228 mvaddstr_and_log_it( g_currentY, 1229 0, 1230 "Using e2label to label your ext2,3 partitions"); 1231 1232 sprintf( tmp, "label-partitions-as-necessary %s < /tmp/fstab", g_mountlist_fname ); 1233 res = run_program_and_log_output( tmp, TRUE ); 1234 if ( res ) 1235 { 1236 log_to_screen( "label-partitions-as-necessary returned an error" ); 1237 mvaddstr_and_log_it( g_currentY++, 74, "Failed." ); 1238 } 1239 else 1240 { 1241 mvaddstr_and_log_it( g_currentY++, 74, "Done." ); 1242 } 1243 retval += res; 1244 1245 after_the_nuke: 1246 if (retval) 1247 { 1248 log_to_screen("Errors occurred during the nuke phase."); 1249 } 1250 else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE")) // Bruno's thing 1251 { 1252 log_to_screen("PC was restored successfully. Thank you for using Mondo Rescue."); 1253 log_to_screen("Please visit http://www.mondorescue.org and thank the dev team."); 1254 } 1255 else 1256 { 1257 #ifdef FREELOADER 1258 success_message(); 1259 #else 1260 log_to_screen("PC was restored successfully!"); 1261 #endif 1262 } 1263 g_I_have_just_nuked = TRUE; 1240 } 1241 g_I_have_just_nuked = TRUE; 1264 1242 /* 1265 1243 if (!boot_loader_installed && !does_file_exist(DO_MBR_PLEASE)) … … 1269 1247 } 1270 1248 */ 1271 return( retval);1249 return (retval); 1272 1250 } 1273 1251 … … 1284 1262 * @return 0 for success, or the number of errors encountered. 1285 1263 */ 1286 int 1287 restore_to_live_filesystem( struct s_bkpinfo *bkpinfo ) 1264 int restore_to_live_filesystem(struct s_bkpinfo *bkpinfo) 1288 1265 { 1289 1266 int retval = 0; 1290 1267 1291 1268 /** malloc **/ 1292 1293 1294 1269 char *old_restpath; 1270 1271 struct mountlist_itself *mountlist; 1295 1272 // static 1296 struct raidlist_itself *raidlist; 1297 struct s_node *filelist; 1298 1299 log_msg(1, "restore_to_live_filesystem() - starting"); 1300 assert(bkpinfo!=NULL); 1301 malloc_string(old_restpath); 1302 mountlist = malloc(sizeof(struct mountlist_itself)); 1303 raidlist = malloc(sizeof(struct raidlist_itself)); 1304 if (!mountlist || !raidlist) { fatal_error("Cannot malloc() mountlist and/or raidlist"); } 1305 1306 strcpy(bkpinfo->restore_path, "/"); 1307 if ( !g_restoring_live_from_cd) 1308 { 1309 popup_and_OK("Please insert tape/CD/boot floppy, then hit 'OK' to continue."); 1310 sleep( 1 ); 1311 } 1312 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 1313 log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device ); 1314 if ( !bkpinfo->media_device[0] ) 1315 { 1316 log_msg(2, "Warning - failed to find media dev"); 1317 } 1318 1319 1320 log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir); 1321 1322 open_evalcall_form("Thinking..."); 1323 1324 get_cfg_file_from_archive_or_bust ( bkpinfo ); 1325 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 1326 load_mountlist( mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo 1327 1328 close_evalcall_form(); 1329 retval = load_mountlist(mountlist, g_mountlist_fname ); 1330 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME ); 1331 filelist = process_filelist_and_biggielist( bkpinfo ); 1332 if ( filelist ) 1333 { 1334 save_filelist(filelist, "/tmp/selected-files.txt"); 1335 strcpy( old_restpath, bkpinfo->restore_path ); 1336 if ( popup_and_get_string( "Restore path", 1337 "Restore files to where? )", 1338 bkpinfo->restore_path, MAX_STR_LEN/4 ) ) 1339 { 1340 iamhere("Restoring everything"); 1341 retval += restore_everything( bkpinfo, filelist ); 1342 free_filelist( filelist ); 1343 strcpy(bkpinfo->restore_path, old_restpath); 1344 } 1345 else 1346 { 1347 free_filelist(filelist); 1348 } 1349 strcpy(bkpinfo->restore_path, old_restpath); 1350 } 1351 if ( IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type ) ) 1352 { 1353 log_msg(2, "I probably don't need to unmount or eject the CD-ROM but I'm doing it anyway."); 1354 } 1355 run_program_and_log_output( "umount "MNT_CDROM, FALSE ); 1356 if (!bkpinfo->please_dont_eject) { eject_device( bkpinfo->media_device ); } 1357 paranoid_free(old_restpath); 1358 free(mountlist); 1359 free(raidlist); 1360 return( retval ); 1273 struct raidlist_itself *raidlist; 1274 struct s_node *filelist; 1275 1276 log_msg(1, "restore_to_live_filesystem() - starting"); 1277 assert(bkpinfo != NULL); 1278 malloc_string(old_restpath); 1279 mountlist = malloc(sizeof(struct mountlist_itself)); 1280 raidlist = malloc(sizeof(struct raidlist_itself)); 1281 if (!mountlist || !raidlist) { 1282 fatal_error("Cannot malloc() mountlist and/or raidlist"); 1283 } 1284 1285 strcpy(bkpinfo->restore_path, "/"); 1286 if (!g_restoring_live_from_cd) { 1287 popup_and_OK 1288 ("Please insert tape/CD/boot floppy, then hit 'OK' to continue."); 1289 sleep(1); 1290 } 1291 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 1292 log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device); 1293 if (!bkpinfo->media_device[0]) { 1294 log_msg(2, "Warning - failed to find media dev"); 1295 } 1296 1297 1298 log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir); 1299 1300 open_evalcall_form("Thinking..."); 1301 1302 get_cfg_file_from_archive_or_bust(bkpinfo); 1303 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 1304 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo 1305 1306 close_evalcall_form(); 1307 retval = load_mountlist(mountlist, g_mountlist_fname); 1308 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 1309 filelist = process_filelist_and_biggielist(bkpinfo); 1310 if (filelist) { 1311 save_filelist(filelist, "/tmp/selected-files.txt"); 1312 strcpy(old_restpath, bkpinfo->restore_path); 1313 if (popup_and_get_string("Restore path", 1314 "Restore files to where? )", 1315 bkpinfo->restore_path, MAX_STR_LEN / 4)) { 1316 iamhere("Restoring everything"); 1317 retval += restore_everything(bkpinfo, filelist); 1318 free_filelist(filelist); 1319 strcpy(bkpinfo->restore_path, old_restpath); 1320 } else { 1321 free_filelist(filelist); 1322 } 1323 strcpy(bkpinfo->restore_path, old_restpath); 1324 } 1325 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1326 log_msg(2, 1327 "I probably don't need to unmount or eject the CD-ROM but I'm doing it anyway."); 1328 } 1329 run_program_and_log_output("umount " MNT_CDROM, FALSE); 1330 if (!bkpinfo->please_dont_eject) { 1331 eject_device(bkpinfo->media_device); 1332 } 1333 paranoid_free(old_restpath); 1334 free(mountlist); 1335 free(raidlist); 1336 return (retval); 1361 1337 } 1362 1338 … … 1386 1362 int 1387 1363 restore_a_biggiefile_from_CD(struct s_bkpinfo *bkpinfo, 1388 long bigfileno, 1389 struct s_node*filelist, char*pathname_of_last_file_restored) 1364 long bigfileno, 1365 struct s_node *filelist, 1366 char *pathname_of_last_file_restored) 1390 1367 { 1391 1392 1393 1394 1368 FILE *fin; 1369 FILE *fout; 1370 FILE *fbzip2; 1371 1395 1372 /** malloc ***/ 1396 char *checksum, *outfile_fname, *tmp, *bzip2_command, *partimagehack_command, *suffix, *sz_devfile; 1397 char *bigblk;1398 char *p;1399 int retval = 0;1400 int finished = FALSE;1401 long sliceno;1402 long siz;1403 char partimagehack_fifo[MAX_STR_LEN];1404 char *file_to_openout = NULL;1405 struct s_filename_and_lstat_info biggiestruct;1406 struct utimbuf the_utime_buf, *ubuf;1407 bool use_partimage_hack=FALSE;1408 pid_t pid;1409 int res=0;1410 int old_loglevel;1411 char sz_msg[MAX_STR_LEN];1412 struct s_node *node;1413 1414 old_loglevel = g_loglevel; 1415 ubuf = &the_utime_buf;1416 assert(bkpinfo!=NULL);1417 1418 malloc_string(checksum); 1419 malloc_string(outfile_fname);1420 malloc_string(tmp);1421 malloc_string(bzip2_command);1422 malloc_string(partimagehack_command);1423 malloc_string(suffix);1424 malloc_string(sz_devfile);1425 1426 pathname_of_last_file_restored[0] = '\0'; 1427 if( !(bigblk = malloc( TAPE_BLOCK_SIZE ) ) ) 1428 1429 1430 1431 1432 if ( !(fin = fopen( slice_fname( bigfileno, 0, ARCHIVES_PATH, ""), "r" ) ) ) 1433 { 1434 log_to_screen( "Cannot even open bigfile's info file");1435 return( 1 ); 1436 } 1437 1438 memset((void*)&biggiestruct, 0, sizeof(biggiestruct)); 1439 if ( fread((void*)&biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct)) 1440 { 1441 log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d", bigfileno+1);1442 1443 1444 1445 1446 1447 if ( !checksum[0]) 1448 { 1449 sprintf(tmp,"Warning - bigfile %ld does not have a checksum",bigfileno+1);1450 1451 1452 1453 1454 if (!strncmp ( biggiestruct.filename, "/dev/", 5))// Whether NTFS or not :)1455 { strcpy( outfile_fname, biggiestruct.filename); } 1456 else 1457 { sprintf( outfile_fname, "%s/%s", bkpinfo->restore_path, biggiestruct.filename ); } 1458 1459 /* skip file if we have a selective restore subset & it doesn't match */ 1460 if (filelist != NULL) 1461 { 1462 node = find_string_at_node(filelist, biggiestruct.filename); 1463 if (!node) 1464 { 1465 log_msg(0, "Skipping %s (name isn't in filelist)", biggiestruct.filename); 1466 pathname_of_last_file_restored[0] = '\0'; 1467 return (0);1468 } 1469 else if (!(node->selected)) 1470 1471 log_msg(1, "Skipping %s (name isn't in biggielist subset)", biggiestruct.filename);1472 pathname_of_last_file_restored[0] = '\0';1473 return( 0 );1474 } 1475 1476 /* otherwise, continue */ 1477 1478 log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename); 1479 if (biggiestruct.use_partimagehack) 1480 1481 if (strncmp ( biggiestruct.filename, "/dev/", 5)) 1482 { 1483 log_msg(1,"I was in error when I set biggiestruct.use_partimagehack to TRUE.");1484 1485 1486 }1487 1488 1489 if (biggiestruct.use_partimagehack)// if it's an NTFS device1373 char *checksum, *outfile_fname, *tmp, *bzip2_command, 1374 *partimagehack_command, *suffix, *sz_devfile; 1375 char *bigblk; 1376 char *p; 1377 int retval = 0; 1378 int finished = FALSE; 1379 long sliceno; 1380 long siz; 1381 char partimagehack_fifo[MAX_STR_LEN]; 1382 char *file_to_openout = NULL; 1383 struct s_filename_and_lstat_info biggiestruct; 1384 struct utimbuf the_utime_buf, *ubuf; 1385 bool use_partimage_hack = FALSE; 1386 pid_t pid; 1387 int res = 0; 1388 int old_loglevel; 1389 char sz_msg[MAX_STR_LEN]; 1390 struct s_node *node; 1391 1392 old_loglevel = g_loglevel; 1393 ubuf = &the_utime_buf; 1394 assert(bkpinfo != NULL); 1395 1396 malloc_string(checksum); 1397 malloc_string(outfile_fname); 1398 malloc_string(tmp); 1399 malloc_string(bzip2_command); 1400 malloc_string(partimagehack_command); 1401 malloc_string(suffix); 1402 malloc_string(sz_devfile); 1403 1404 pathname_of_last_file_restored[0] = '\0'; 1405 if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) { 1406 fatal_error("Cannot malloc bigblk"); 1407 } 1408 1409 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) { 1410 log_to_screen("Cannot even open bigfile's info file"); 1411 return (1); 1412 } 1413 1414 memset((void *) &biggiestruct, 0, sizeof(biggiestruct)); 1415 if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) < 1416 sizeof(biggiestruct)) { 1417 log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d", 1418 bigfileno + 1); 1419 } 1420 paranoid_fclose(fin); 1421 1422 strcpy(checksum, biggiestruct.checksum); 1423 1424 if (!checksum[0]) { 1425 sprintf(tmp, "Warning - bigfile %ld does not have a checksum", 1426 bigfileno + 1); 1427 log_msg(3, tmp); 1428 p = checksum; 1429 } 1430 1431 if (!strncmp(biggiestruct.filename, "/dev/", 5)) // Whether NTFS or not :) 1432 { 1433 strcpy(outfile_fname, biggiestruct.filename); 1434 } else { 1435 sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, 1436 biggiestruct.filename); 1437 } 1438 1439 /* skip file if we have a selective restore subset & it doesn't match */ 1440 if (filelist != NULL) { 1441 node = find_string_at_node(filelist, biggiestruct.filename); 1442 if (!node) { 1443 log_msg(0, "Skipping %s (name isn't in filelist)", 1444 biggiestruct.filename); 1445 pathname_of_last_file_restored[0] = '\0'; 1446 return (0); 1447 } else if (!(node->selected)) { 1448 log_msg(1, "Skipping %s (name isn't in biggielist subset)", 1449 biggiestruct.filename); 1450 pathname_of_last_file_restored[0] = '\0'; 1451 return (0); 1452 } 1453 } 1454 /* otherwise, continue */ 1455 1456 log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename); 1457 if (biggiestruct.use_partimagehack) { 1458 if (strncmp(biggiestruct.filename, "/dev/", 5)) { 1459 log_msg(1, 1460 "I was in error when I set biggiestruct.use_partimagehack to TRUE."); 1461 log_msg(1, "%s isn't even in /dev", biggiestruct.filename); 1462 biggiestruct.use_partimagehack = FALSE; 1463 } 1464 } 1465 1466 if (biggiestruct.use_partimagehack) // if it's an NTFS device 1490 1467 // if (!strncmp ( biggiestruct.filename, "/dev/", 5)) 1491 {1492 g_loglevel = 4;1493 use_partimage_hack = TRUE;1494 log_msg(2, "Calling partimagehack in background because %s is an NTFS /dev entry", outfile_fname);1495 sprintf(sz_devfile, "/tmp/%d.%d.000", (int)(random()%32768), (int)(random()%32768));1496 mkfifo(sz_devfile, 0x770);1497 strcpy(partimagehack_fifo, sz_devfile);1498 file_to_openout = partimagehack_fifo;1499 switch(pid=fork())1500 {1501 case -1: fatal_error("Fork failure");1502 case 0:1503 log_msg(3, "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", biggiestruct.filename, partimagehack_fifo);1504 res=feed_outfrom_partimage(biggiestruct.filename, partimagehack_fifo);1505 // log_msg(3, "CHILD - fip - exiting");1506 exit(res);1507 break;1508 default:1509 log_msg(3, "feed_into_partimage() called in background --- pid=%ld", (long int)(pid));1510 }1511 }1512 else1513 {1514 use_partimage_hack = FALSE;1515 partimagehack_fifo[0] = '\0';1516 file_to_openout = outfile_fname;1517 if ( !does_file_exist( outfile_fname ) ) // yes, it looks weird with the '!' but it's correct that way1518 { make_hole_for_file( outfile_fname ); }1519 }1520 1521 sprintf( tmp, "Reassembling big file %ld (%s)", bigfileno+1, outfile_fname );1522 log_msg(2, tmp );1523 1524 /*1525 last slice is zero-length and uncompressed; when we find it, we stop.1526 We DON'T wait until there are no more slices; if we did that,1527 We might stop at end of CD, not at last slice (which is 0-len and uncompd)1528 */1529 1530 strncpy(pathname_of_last_file_restored, biggiestruct.filename, MAX_STR_LEN-1);1531 pathname_of_last_file_restored[MAX_STR_LEN-1] = '\0';1532 1533 log_msg(3, "file_to_openout = %s", file_to_openout);1534 if ( !(fout = fopen( file_to_openout, "w" ) ) )1535 {1536 log_to_screen( "Cannot openout outfile_fname - hard disk full?");1537 return(1);1538 }1539 log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> partimagehack --> hard disk itself1540 1541 for( sliceno = 1, finished = FALSE; !finished; )1542 {1543 if ( !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"")) && !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"lzo")) && !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"bz2")))1544 1468 { 1545 log_msg(3, "Cannot find a data slice or terminator slice on CD %d", g_current_media_number); 1546 g_current_media_number++; 1547 sprintf( tmp, "Asking for %s #%d so that I may read slice #%ld\n",media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number,sliceno); 1548 log_msg(2, tmp ); 1549 sprintf( tmp, "Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number ); 1550 log_to_screen( tmp ); 1551 insist_on_this_cd_number( bkpinfo, g_current_media_number ); 1552 log_to_screen( "Continuing to restore."); 1553 } 1554 else 1555 { 1556 strcpy(tmp, slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"")); 1557 if (does_file_exist(tmp) && length_of_file(tmp) == 0) 1558 { 1559 log_msg(2, "End of bigfile # %ld (slice %ld is the terminator)", bigfileno + 1, sliceno ); 1560 finished = TRUE; 1561 continue; 1562 } 1563 else 1564 { 1565 if ( does_file_exist(slice_fname(bigfileno, sliceno,ARCHIVES_PATH, "lzo" ) ) ) 1469 g_loglevel = 4; 1470 use_partimage_hack = TRUE; 1471 log_msg(2, 1472 "Calling partimagehack in background because %s is an NTFS /dev entry", 1473 outfile_fname); 1474 sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), 1475 (int) (random() % 32768)); 1476 mkfifo(sz_devfile, 0x770); 1477 strcpy(partimagehack_fifo, sz_devfile); 1478 file_to_openout = partimagehack_fifo; 1479 switch (pid = fork()) { 1480 case -1: 1481 fatal_error("Fork failure"); 1482 case 0: 1483 log_msg(3, 1484 "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", 1485 biggiestruct.filename, partimagehack_fifo); 1486 res = 1487 feed_outfrom_partimage(biggiestruct.filename, 1488 partimagehack_fifo); 1489 // log_msg(3, "CHILD - fip - exiting"); 1490 exit(res); 1491 break; 1492 default: 1493 log_msg(3, 1494 "feed_into_partimage() called in background --- pid=%ld", 1495 (long int) (pid)); 1496 } 1497 } else { 1498 use_partimage_hack = FALSE; 1499 partimagehack_fifo[0] = '\0'; 1500 file_to_openout = outfile_fname; 1501 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way 1566 1502 { 1567 strcpy( bzip2_command, "lzop" ); 1568 strcpy( suffix, "lzo"); 1569 } 1570 else if ( does_file_exist( slice_fname( bigfileno, sliceno, ARCHIVES_PATH, "bz2" ) ) ) 1571 { 1572 strcpy( bzip2_command, "bzip2" ); 1573 strcpy( suffix, "bz2"); 1574 } 1575 else if ( does_file_exist( slice_fname( bigfileno, sliceno, ARCHIVES_PATH, "" ) ) ) 1576 { 1577 strcpy( bzip2_command, "" ); 1578 strcpy( suffix, ""); 1579 } 1580 else 1581 { 1582 log_to_screen( "OK, that's pretty fsck0red..."); 1583 return( 1 ); 1584 } 1585 } 1586 if ( bzip2_command[0] != '\0' ) 1587 { 1588 sprintf( bzip2_command + strlen( bzip2_command ), 1589 " -dc %s 2>> %s", 1590 slice_fname( bigfileno, sliceno, ARCHIVES_PATH, suffix), 1591 MONDO_LOGFILE); 1592 } 1593 else 1594 { 1595 sprintf( bzip2_command, "cat %s 2>> %s", 1596 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix ), 1597 MONDO_LOGFILE ); 1598 } 1599 sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number, bigfileno + 1, sliceno ); 1600 log_msg(2, tmp ); 1601 1602 if (!g_text_mode) 1603 { 1604 newtDrawRootText( 0, g_noof_rows - 2, tmp ); 1605 newtRefresh(); 1606 strip_spaces( tmp ); 1607 update_progress_form( tmp ); 1608 } 1609 if ( !(fbzip2 = popen( bzip2_command, "r" ) ) ) 1610 { 1611 fatal_error( "Can't run popen command"); 1612 } 1613 while( !feof( fbzip2 ) ) 1614 { 1615 siz = fread( bigblk, 1, TAPE_BLOCK_SIZE, fbzip2 ); 1616 if (siz > 0) 1617 { 1618 sprintf(sz_msg, "Read %ld from fbzip2", siz); 1619 siz = fwrite( bigblk, 1, siz, fout); 1620 sprintf(sz_msg + strlen(sz_msg), "; written %ld to fout", siz); 1621 // log_msg(2. sz_msg); 1622 } 1623 } 1624 paranoid_pclose(fbzip2); 1625 1626 1627 sliceno++; 1628 g_current_progress++; 1629 } 1630 } 1503 make_hole_for_file(outfile_fname); 1504 } 1505 } 1506 1507 sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1, 1508 outfile_fname); 1509 log_msg(2, tmp); 1510 1511 /* 1512 last slice is zero-length and uncompressed; when we find it, we stop. 1513 We DON'T wait until there are no more slices; if we did that, 1514 We might stop at end of CD, not at last slice (which is 0-len and uncompd) 1515 */ 1516 1517 strncpy(pathname_of_last_file_restored, biggiestruct.filename, 1518 MAX_STR_LEN - 1); 1519 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0'; 1520 1521 log_msg(3, "file_to_openout = %s", file_to_openout); 1522 if (!(fout = fopen(file_to_openout, "w"))) { 1523 log_to_screen("Cannot openout outfile_fname - hard disk full?"); 1524 return (1); 1525 } 1526 log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> partimagehack --> hard disk itself 1527 1528 for (sliceno = 1, finished = FALSE; !finished;) { 1529 if (!does_file_exist 1530 (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")) 1531 && 1532 !does_file_exist(slice_fname 1533 (bigfileno, sliceno, ARCHIVES_PATH, "lzo")) 1534 && 1535 !does_file_exist(slice_fname 1536 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) { 1537 log_msg(3, 1538 "Cannot find a data slice or terminator slice on CD %d", 1539 g_current_media_number); 1540 g_current_media_number++; 1541 sprintf(tmp, 1542 "Asking for %s #%d so that I may read slice #%ld\n", 1543 media_descriptor_string(bkpinfo->backup_media_type), 1544 g_current_media_number, sliceno); 1545 log_msg(2, tmp); 1546 sprintf(tmp, "Restoring from %s #%d", 1547 media_descriptor_string(bkpinfo->backup_media_type), 1548 g_current_media_number); 1549 log_to_screen(tmp); 1550 insist_on_this_cd_number(bkpinfo, g_current_media_number); 1551 log_to_screen("Continuing to restore."); 1552 } else { 1553 strcpy(tmp, 1554 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")); 1555 if (does_file_exist(tmp) && length_of_file(tmp) == 0) { 1556 log_msg(2, 1557 "End of bigfile # %ld (slice %ld is the terminator)", 1558 bigfileno + 1, sliceno); 1559 finished = TRUE; 1560 continue; 1561 } else { 1562 if (does_file_exist 1563 (slice_fname 1564 (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) { 1565 strcpy(bzip2_command, "lzop"); 1566 strcpy(suffix, "lzo"); 1567 } else 1568 if (does_file_exist 1569 (slice_fname 1570 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) { 1571 strcpy(bzip2_command, "bzip2"); 1572 strcpy(suffix, "bz2"); 1573 } else 1574 if (does_file_exist 1575 (slice_fname 1576 (bigfileno, sliceno, ARCHIVES_PATH, ""))) { 1577 strcpy(bzip2_command, ""); 1578 strcpy(suffix, ""); 1579 } else { 1580 log_to_screen("OK, that's pretty fsck0red..."); 1581 return (1); 1582 } 1583 } 1584 if (bzip2_command[0] != '\0') { 1585 sprintf(bzip2_command + strlen(bzip2_command), 1586 " -dc %s 2>> %s", 1587 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, 1588 suffix), MONDO_LOGFILE); 1589 } else { 1590 sprintf(bzip2_command, "cat %s 2>> %s", 1591 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, 1592 suffix), MONDO_LOGFILE); 1593 } 1594 sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld ", 1595 media_descriptor_string(bkpinfo->backup_media_type), 1596 g_current_media_number, bigfileno + 1, sliceno); 1597 log_msg(2, tmp); 1598 1599 if (!g_text_mode) { 1600 newtDrawRootText(0, g_noof_rows - 2, tmp); 1601 newtRefresh(); 1602 strip_spaces(tmp); 1603 update_progress_form(tmp); 1604 } 1605 if (!(fbzip2 = popen(bzip2_command, "r"))) { 1606 fatal_error("Can't run popen command"); 1607 } 1608 while (!feof(fbzip2)) { 1609 siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2); 1610 if (siz > 0) { 1611 sprintf(sz_msg, "Read %ld from fbzip2", siz); 1612 siz = fwrite(bigblk, 1, siz, fout); 1613 sprintf(sz_msg + strlen(sz_msg), 1614 "; written %ld to fout", siz); 1615 // log_msg(2. sz_msg); 1616 } 1617 } 1618 paranoid_pclose(fbzip2); 1619 1620 1621 sliceno++; 1622 g_current_progress++; 1623 } 1624 } 1631 1625 /* 1632 1626 memset(bigblk, TAPE_BLOCK_SIZE, 1); // This all looks very fishy... … … 1636 1630 fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout); 1637 1631 */ 1638 paranoid_fclose( fout ); 1639 g_loglevel = old_loglevel; 1640 1641 if (use_partimage_hack) 1642 { 1643 log_msg(3, "Waiting for partimage to finish"); 1644 sprintf(tmp, " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null"); 1645 while(system(tmp) == 0) 1646 { sleep(1); } 1647 log_it("OK, partimage has really finished"); 1648 } 1649 1650 if (strcmp(outfile_fname, "/dev/null")) 1651 { 1652 chown( outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid ); 1653 chmod( outfile_fname, biggiestruct.properties.st_mode ); 1654 ubuf->actime = biggiestruct.properties.st_atime; 1655 ubuf->modtime= biggiestruct.properties.st_mtime; 1656 utime( outfile_fname, ubuf ); 1657 } 1658 paranoid_free( bigblk ); 1659 paranoid_free(checksum); 1660 paranoid_free(outfile_fname); 1661 paranoid_free(tmp); 1662 paranoid_free(bzip2_command); 1663 paranoid_free(partimagehack_command); 1664 paranoid_free(suffix); 1665 paranoid_free(sz_devfile); 1666 1667 return( retval ); 1632 paranoid_fclose(fout); 1633 g_loglevel = old_loglevel; 1634 1635 if (use_partimage_hack) { 1636 log_msg(3, "Waiting for partimage to finish"); 1637 sprintf(tmp, 1638 " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null"); 1639 while (system(tmp) == 0) { 1640 sleep(1); 1641 } 1642 log_it("OK, partimage has really finished"); 1643 } 1644 1645 if (strcmp(outfile_fname, "/dev/null")) { 1646 chown(outfile_fname, biggiestruct.properties.st_uid, 1647 biggiestruct.properties.st_gid); 1648 chmod(outfile_fname, biggiestruct.properties.st_mode); 1649 ubuf->actime = biggiestruct.properties.st_atime; 1650 ubuf->modtime = biggiestruct.properties.st_mtime; 1651 utime(outfile_fname, ubuf); 1652 } 1653 paranoid_free(bigblk); 1654 paranoid_free(checksum); 1655 paranoid_free(outfile_fname); 1656 paranoid_free(tmp); 1657 paranoid_free(bzip2_command); 1658 paranoid_free(partimagehack_command); 1659 paranoid_free(suffix); 1660 paranoid_free(sz_devfile); 1661 1662 return (retval); 1668 1663 } 1669 1664 … … 1688 1683 * @bug orig_checksum and biggiefile_size are unused (except to check that they are non-NULL). 1689 1684 */ 1690 int 1691 restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, 1692 char *orig_bf_fname, 1693 long biggiefile_number, 1694 char *orig_checksum, //UNUSED 1695 long long biggiefile_size, //UNUSED 1696 struct s_node *filelist, int use_partimagehack, 1697 char*pathname_of_last_file_restored) 1685 int restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, char *orig_bf_fname, long biggiefile_number, char *orig_checksum, //UNUSED 1686 long long biggiefile_size, //UNUSED 1687 struct s_node *filelist, 1688 int use_partimagehack, 1689 char *pathname_of_last_file_restored) 1698 1690 { 1699 1700 1691 FILE *pout; 1692 FILE *fin; 1701 1693 1702 1694 /** mallocs ********/ 1703 char *tmp; 1704 char *command; 1705 char *outfile_fname; 1706 char *partimagehack_command; 1707 char *sz_devfile; 1708 char *partimagehack_fifo; 1709 char *file_to_openout = NULL; 1710 1711 struct s_node *node; 1712 1713 int old_loglevel; 1714 long current_slice_number = 0; 1715 int retval = 0; 1716 int res = 0; 1717 int ctrl_chr = '\0'; 1718 long long slice_siz; 1719 bool dummy_restore = FALSE; 1720 bool use_partimage_hack=FALSE; 1721 pid_t pid; 1722 struct s_filename_and_lstat_info biggiestruct; 1723 struct utimbuf the_utime_buf, *ubuf; 1724 ubuf = &the_utime_buf; 1725 1726 malloc_string(tmp); 1727 malloc_string(partimagehack_fifo); 1728 malloc_string(outfile_fname); 1729 malloc_string(command); 1730 malloc_string(sz_devfile); 1731 malloc_string(partimagehack_command); 1732 old_loglevel = g_loglevel; 1733 assert(bkpinfo!=NULL); 1734 assert(orig_bf_fname!=NULL); 1735 assert(orig_checksum!=NULL); 1736 1737 pathname_of_last_file_restored[0] = '\0'; 1738 if (use_partimagehack == BLK_START_A_PIHBIGGIE) 1739 { 1740 use_partimagehack = 1; 1741 log_msg(1, "%s --- pih=YES", orig_bf_fname); 1742 } 1743 else if (use_partimagehack == BLK_START_A_NORMBIGGIE) 1744 { 1745 use_partimagehack = 0; 1746 log_msg(1, "%s --- pih=NO", orig_bf_fname); 1747 } 1748 else 1749 { 1750 use_partimagehack = 0; 1751 log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname); 1752 } 1753 1754 strncpy(pathname_of_last_file_restored, orig_bf_fname, MAX_STR_LEN-1); 1755 pathname_of_last_file_restored[MAX_STR_LEN-1] = '\0'; 1756 1757 /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */ 1758 1759 if (filelist != NULL) 1760 { 1761 node = find_string_at_node(filelist, orig_bf_fname); 1762 if (!node) 1763 { 1764 dummy_restore = TRUE; 1765 log_msg(1, "Skipping big file %ld (%s) - not in biggielist subset", biggiefile_number+1, orig_bf_fname); 1766 pathname_of_last_file_restored[0] = '\0'; 1767 } 1768 else if (!(node->selected)) 1769 { 1770 dummy_restore = TRUE; 1771 log_msg(1, "Skipping %s (name isn't in biggielist subset)", orig_bf_fname); 1772 pathname_of_last_file_restored[0] = '\0'; 1773 } 1774 } 1775 1776 if (use_partimagehack) 1777 { 1778 if (strncmp ( orig_bf_fname, "/dev/", 5)) 1779 { 1780 log_msg(1, "I was in error when I set use_partimagehack to TRUE."); 1781 log_msg(1, "%s isn't even in /dev", orig_bf_fname); 1782 use_partimagehack = FALSE; 1783 } 1784 } 1785 1786 if (use_partimagehack) 1787 { 1788 g_loglevel = 4; 1789 strcpy(outfile_fname, orig_bf_fname); 1790 use_partimage_hack = TRUE; 1791 log_msg(2, "Calling partimagehack in background because %s is a /dev entry", outfile_fname); 1792 sprintf(sz_devfile, "/tmp/%d.%d.000", (int)(random()%32768), (int)(random()%32768)); 1793 mkfifo(sz_devfile, 0x770); 1794 strcpy(partimagehack_fifo, sz_devfile); 1795 file_to_openout = partimagehack_fifo; 1796 switch(pid=fork()) 1797 { 1798 case -1: fatal_error("Fork failure"); 1799 case 0: 1800 log_msg(3, "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", outfile_fname, partimagehack_fifo); 1801 res=feed_outfrom_partimage(outfile_fname, partimagehack_fifo); 1802 // log_msg(3, "CHILD - fip - exiting"); 1803 exit(res); 1804 break; 1805 default: 1806 log_msg(3, "feed_into_partimage() called in background --- pid=%ld", (long int)(pid)); 1807 } 1808 } 1809 else 1810 { 1811 if (!strncmp ( orig_bf_fname, "/dev/", 5)) // non-NTFS partition 1812 { strcpy(outfile_fname, orig_bf_fname); } 1813 else // biggiefile 1814 { sprintf( outfile_fname, "%s/%s", bkpinfo->restore_path, orig_bf_fname ); } 1815 use_partimage_hack = FALSE; 1816 partimagehack_fifo[0] = '\0'; 1817 file_to_openout = outfile_fname; 1818 if ( !does_file_exist( outfile_fname ) ) // yes, it looks weird with the '!' but it's correct that way 1819 { make_hole_for_file( outfile_fname ); } 1820 sprintf(tmp, "Reassembling big file %ld (%s)", biggiefile_number + 1, orig_bf_fname ); 1821 log_msg(2, tmp ); 1822 } 1823 1824 if (dummy_restore) 1825 { sprintf( outfile_fname, "/dev/null" ); } 1826 1827 if ( !bkpinfo->zip_exe[0] ) 1828 { 1829 sprintf(command, "cat > \"%s\"", file_to_openout); 1830 } 1831 else 1832 { 1833 sprintf(command,"%s -dc > \"%s\" 2>> %s",bkpinfo->zip_exe, file_to_openout, MONDO_LOGFILE); 1834 } 1835 sprintf(tmp,"Pipe command = '%s'",command); 1836 log_msg(3, tmp); 1837 1838 /* restore biggiefile, one slice at a time */ 1839 if ( !( pout = popen(command, "w" ) ) ) 1840 { 1841 fatal_error( "Cannot pipe out" ); 1842 } 1843 for( res = read_header_block_from_stream( &slice_siz, tmp, &ctrl_chr); ctrl_chr!=BLK_STOP_A_BIGGIE; res=read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr ) ) 1844 { 1845 if ( ctrl_chr != BLK_START_AN_AFIO_OR_SLICE ) 1846 { 1847 wrong_marker( BLK_START_AN_AFIO_OR_SLICE,ctrl_chr ); 1848 } 1849 sprintf( tmp,"Working on file #%ld, slice #%ld ", 1850 biggiefile_number + 1, 1851 current_slice_number); 1852 log_msg(2, tmp); 1853 if (!g_text_mode) 1854 { 1855 newtDrawRootText( 0, g_noof_rows - 2, tmp); 1856 newtRefresh(); 1857 } 1858 strip_spaces( tmp ); 1859 update_progress_form( tmp ); 1860 if ( current_slice_number == 0 ) 1861 { 1862 res = read_file_from_stream_to_file( bkpinfo,"/tmp/biggie-blah.txt",slice_siz); 1863 if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) 1864 { log_OS_error("blah blah"); } 1865 else 1866 { 1867 if ( fread( (void*)&biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct)) 1868 { 1869 log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d", biggiefile_number + 1); 1870 } 1871 paranoid_fclose(fin); 1872 } 1873 } 1874 else 1875 { 1876 res = read_file_from_stream_to_stream( bkpinfo, pout, slice_siz ); 1877 } 1878 retval += res; 1879 res = read_header_block_from_stream( &slice_siz, tmp, &ctrl_chr ); 1880 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) 1881 { 1882 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 1883 } 1884 current_slice_number++; 1885 g_current_progress++; 1886 } 1887 paranoid_pclose(pout); 1888 1889 log_msg(1, "pathname_of_last_file_restored is now %s", pathname_of_last_file_restored); 1890 1891 if (use_partimage_hack) 1892 { 1893 log_msg(3, "Waiting for partimage to finish"); 1894 sprintf(tmp, " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null"); 1895 while(system(tmp) == 0) 1896 { sleep(1); } 1897 log_msg(3, "OK, partimage has really finished"); 1898 } 1899 1900 log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename); 1901 log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum); 1902 if (strcmp(outfile_fname, "/dev/null")) 1903 { 1904 chmod(outfile_fname, biggiestruct.properties.st_mode); 1905 chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid); 1906 ubuf->actime = biggiestruct.properties.st_atime; 1907 ubuf->modtime= biggiestruct.properties.st_mtime; 1908 utime( outfile_fname, ubuf ); 1909 } 1910 1911 paranoid_free(tmp); 1912 paranoid_free(outfile_fname); 1913 paranoid_free(command); 1914 paranoid_free(partimagehack_command); 1915 paranoid_free(sz_devfile); 1916 paranoid_free(partimagehack_fifo); 1917 g_loglevel = old_loglevel; 1918 return(retval); 1695 char *tmp; 1696 char *command; 1697 char *outfile_fname; 1698 char *partimagehack_command; 1699 char *sz_devfile; 1700 char *partimagehack_fifo; 1701 char *file_to_openout = NULL; 1702 1703 struct s_node *node; 1704 1705 int old_loglevel; 1706 long current_slice_number = 0; 1707 int retval = 0; 1708 int res = 0; 1709 int ctrl_chr = '\0'; 1710 long long slice_siz; 1711 bool dummy_restore = FALSE; 1712 bool use_partimage_hack = FALSE; 1713 pid_t pid; 1714 struct s_filename_and_lstat_info biggiestruct; 1715 struct utimbuf the_utime_buf, *ubuf; 1716 ubuf = &the_utime_buf; 1717 1718 malloc_string(tmp); 1719 malloc_string(partimagehack_fifo); 1720 malloc_string(outfile_fname); 1721 malloc_string(command); 1722 malloc_string(sz_devfile); 1723 malloc_string(partimagehack_command); 1724 old_loglevel = g_loglevel; 1725 assert(bkpinfo != NULL); 1726 assert(orig_bf_fname != NULL); 1727 assert(orig_checksum != NULL); 1728 1729 pathname_of_last_file_restored[0] = '\0'; 1730 if (use_partimagehack == BLK_START_A_PIHBIGGIE) { 1731 use_partimagehack = 1; 1732 log_msg(1, "%s --- pih=YES", orig_bf_fname); 1733 } else if (use_partimagehack == BLK_START_A_NORMBIGGIE) { 1734 use_partimagehack = 0; 1735 log_msg(1, "%s --- pih=NO", orig_bf_fname); 1736 } else { 1737 use_partimagehack = 0; 1738 log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname); 1739 } 1740 1741 strncpy(pathname_of_last_file_restored, orig_bf_fname, 1742 MAX_STR_LEN - 1); 1743 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0'; 1744 1745 /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */ 1746 1747 if (filelist != NULL) { 1748 node = find_string_at_node(filelist, orig_bf_fname); 1749 if (!node) { 1750 dummy_restore = TRUE; 1751 log_msg(1, 1752 "Skipping big file %ld (%s) - not in biggielist subset", 1753 biggiefile_number + 1, orig_bf_fname); 1754 pathname_of_last_file_restored[0] = '\0'; 1755 } else if (!(node->selected)) { 1756 dummy_restore = TRUE; 1757 log_msg(1, "Skipping %s (name isn't in biggielist subset)", 1758 orig_bf_fname); 1759 pathname_of_last_file_restored[0] = '\0'; 1760 } 1761 } 1762 1763 if (use_partimagehack) { 1764 if (strncmp(orig_bf_fname, "/dev/", 5)) { 1765 log_msg(1, 1766 "I was in error when I set use_partimagehack to TRUE."); 1767 log_msg(1, "%s isn't even in /dev", orig_bf_fname); 1768 use_partimagehack = FALSE; 1769 } 1770 } 1771 1772 if (use_partimagehack) { 1773 g_loglevel = 4; 1774 strcpy(outfile_fname, orig_bf_fname); 1775 use_partimage_hack = TRUE; 1776 log_msg(2, 1777 "Calling partimagehack in background because %s is a /dev entry", 1778 outfile_fname); 1779 sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), 1780 (int) (random() % 32768)); 1781 mkfifo(sz_devfile, 0x770); 1782 strcpy(partimagehack_fifo, sz_devfile); 1783 file_to_openout = partimagehack_fifo; 1784 switch (pid = fork()) { 1785 case -1: 1786 fatal_error("Fork failure"); 1787 case 0: 1788 log_msg(3, 1789 "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", 1790 outfile_fname, partimagehack_fifo); 1791 res = 1792 feed_outfrom_partimage(outfile_fname, partimagehack_fifo); 1793 // log_msg(3, "CHILD - fip - exiting"); 1794 exit(res); 1795 break; 1796 default: 1797 log_msg(3, 1798 "feed_into_partimage() called in background --- pid=%ld", 1799 (long int) (pid)); 1800 } 1801 } else { 1802 if (!strncmp(orig_bf_fname, "/dev/", 5)) // non-NTFS partition 1803 { 1804 strcpy(outfile_fname, orig_bf_fname); 1805 } else // biggiefile 1806 { 1807 sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, 1808 orig_bf_fname); 1809 } 1810 use_partimage_hack = FALSE; 1811 partimagehack_fifo[0] = '\0'; 1812 file_to_openout = outfile_fname; 1813 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way 1814 { 1815 make_hole_for_file(outfile_fname); 1816 } 1817 sprintf(tmp, "Reassembling big file %ld (%s)", 1818 biggiefile_number + 1, orig_bf_fname); 1819 log_msg(2, tmp); 1820 } 1821 1822 if (dummy_restore) { 1823 sprintf(outfile_fname, "/dev/null"); 1824 } 1825 1826 if (!bkpinfo->zip_exe[0]) { 1827 sprintf(command, "cat > \"%s\"", file_to_openout); 1828 } else { 1829 sprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe, 1830 file_to_openout, MONDO_LOGFILE); 1831 } 1832 sprintf(tmp, "Pipe command = '%s'", command); 1833 log_msg(3, tmp); 1834 1835 /* restore biggiefile, one slice at a time */ 1836 if (!(pout = popen(command, "w"))) { 1837 fatal_error("Cannot pipe out"); 1838 } 1839 for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr); 1840 ctrl_chr != BLK_STOP_A_BIGGIE; 1841 res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr)) { 1842 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 1843 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 1844 } 1845 sprintf(tmp, "Working on file #%ld, slice #%ld ", 1846 biggiefile_number + 1, current_slice_number); 1847 log_msg(2, tmp); 1848 if (!g_text_mode) { 1849 newtDrawRootText(0, g_noof_rows - 2, tmp); 1850 newtRefresh(); 1851 } 1852 strip_spaces(tmp); 1853 update_progress_form(tmp); 1854 if (current_slice_number == 0) { 1855 res = 1856 read_file_from_stream_to_file(bkpinfo, 1857 "/tmp/biggie-blah.txt", 1858 slice_siz); 1859 if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) { 1860 log_OS_error("blah blah"); 1861 } else { 1862 if (fread 1863 ((void *) &biggiestruct, 1, sizeof(biggiestruct), 1864 fin) < sizeof(biggiestruct)) { 1865 log_msg(2, 1866 "Warning - unable to get biggiestruct of bigfile #%d", 1867 biggiefile_number + 1); 1868 } 1869 paranoid_fclose(fin); 1870 } 1871 } else { 1872 res = 1873 read_file_from_stream_to_stream(bkpinfo, pout, slice_siz); 1874 } 1875 retval += res; 1876 res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr); 1877 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { 1878 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 1879 } 1880 current_slice_number++; 1881 g_current_progress++; 1882 } 1883 paranoid_pclose(pout); 1884 1885 log_msg(1, "pathname_of_last_file_restored is now %s", 1886 pathname_of_last_file_restored); 1887 1888 if (use_partimage_hack) { 1889 log_msg(3, "Waiting for partimage to finish"); 1890 sprintf(tmp, 1891 " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null"); 1892 while (system(tmp) == 0) { 1893 sleep(1); 1894 } 1895 log_msg(3, "OK, partimage has really finished"); 1896 } 1897 1898 log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename); 1899 log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum); 1900 if (strcmp(outfile_fname, "/dev/null")) { 1901 chmod(outfile_fname, biggiestruct.properties.st_mode); 1902 chown(outfile_fname, biggiestruct.properties.st_uid, 1903 biggiestruct.properties.st_gid); 1904 ubuf->actime = biggiestruct.properties.st_atime; 1905 ubuf->modtime = biggiestruct.properties.st_mtime; 1906 utime(outfile_fname, ubuf); 1907 } 1908 1909 paranoid_free(tmp); 1910 paranoid_free(outfile_fname); 1911 paranoid_free(command); 1912 paranoid_free(partimagehack_command); 1913 paranoid_free(sz_devfile); 1914 paranoid_free(partimagehack_fifo); 1915 g_loglevel = old_loglevel; 1916 return (retval); 1919 1917 } 1920 1918 … … 1938 1936 int 1939 1937 restore_a_tarball_from_CD(char *tarball_fname, 1940 long current_tarball_number,1941 struct s_node*filelist)1938 long current_tarball_number, 1939 struct s_node *filelist) 1942 1940 { 1943 1944 1945 1941 int retval = 0; 1942 int res; 1943 char *p; 1946 1944 1947 1945 /** malloc **/ 1948 1949 1950 1951 1952 1953 1954 1955 long matches=0;1956 1957 1958 1946 char *command; 1947 char *tmp; 1948 char *filelist_name; 1949 char *filelist_subset_fname; 1950 char *executable; 1951 char *temp_log; 1952 char screen_message[100]; 1953 long matches = 0; 1954 bool use_star; 1955 char *xattr_fname; 1956 char *acl_fname; 1959 1957 // char files_to_restore_this_time_fname[MAX_STR_LEN]; 1960 1958 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE;1959 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 1960 malloc_string(command); 1961 malloc_string(tmp); 1962 malloc_string(filelist_name); 1963 malloc_string(filelist_subset_fname); 1964 malloc_string(executable); 1965 malloc_string(temp_log); 1966 malloc_string(xattr_fname); 1967 malloc_string(acl_fname); 1968 1969 log_msg(5, "Entering"); 1970 filelist_subset_fname[0] = '\0'; 1971 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 1974 1972 // sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random()); 1975 1976 1977 sprintf(temp_log, "/tmp/%d.%d", (int)(random()%32768), (int)(random()%32768)); 1978 1979 sprintf(filelist_name, MNT_CDROM"/archives/filelist.%ld",current_tarball_number); 1980 if ( length_of_file( filelist_name ) <= 2 ) 1981 { 1982 log_msg(2, "There are _zero_ files in filelist '%s'", filelist_name); 1983 log_msg(2, "This is a bit silly (ask Hugo to fix mondo-makefilelist, please)"); 1984 log_msg(2, "but it's non-critical. It's cosmetic. Don't worry about it.");1985 retval=0; 1986 goto leave_sub;1987 } 1988 if ( count_lines_in_file(filelist_name) <= 0 || length_of_file( tarball_fname ) <= 0 ) 1989 { 1990 log_msg(3, "length_of_file(%s) = %ld", tarball_fname, length_of_file(tarball_fname));1991 sprintf(tmp,"Unable to restore fileset #%ld (CD I/O error)",current_tarball_number); 1992 log_to_screen(tmp); 1993 retval=1; 1994 goto leave_sub; 1995 } 1996 1997 if (filelist) 1998 { 1999 sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", current_tarball_number);2000 if ((matches=save_filelist_entries_in_common 2001 (filelist_name, filelist, filelist_subset_fname, use_star)) 2002 <= 0) 2003 {2004 sprintf(tmp, "Skipping fileset %ld", current_tarball_number);2005 log_msg(1, tmp);2006 }2007 else 2008 { 2009 log_msg(3, "Saved fileset %ld's subset to %s", current_tarball_number, filelist_subset_fname);2010 }2011 sprintf(screen_message, "Tarball #%ld --- %ld matches", current_tarball_number, matches);2012 log_to_screen(screen_message);2013 } 2014 else 2015 { 2016 filelist_subset_fname[0] = '\0'; 2017 } 2018 2019 if (filelist == NULL || matches>0) 2020 2021 sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, MNT_CDROM"/archives", current_tarball_number);2022 sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM"/archives", current_tarball_number); 2023 if ( strstr( tarball_fname, ".bz2" ) ) 2024 2025 strcpy(executable,"bzip2"); 2026 } 2027 else if ( strstr( tarball_fname, ".lzo") ) 2028 { 2029 strcpy( executable,"lzop"); 2030 } 2031 else 2032 { 2033 executable[0] = '\0'; 2034 } 2035 if (executable[0]) 2036 2037 sprintf( tmp, "which %s > /dev/null 2> /dev/null", executable);2038 if ( run_program_and_log_output( tmp, FALSE ) ) 2039 { 2040 log_to_screen("(compare_a_tarball) Compression program not found - oh no!");2041 2042 2043 2044 2045 1973 sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING); 1974 run_program_and_log_output(command, 9); 1975 sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768), 1976 (int) (random() % 32768)); 1977 1978 sprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld", 1979 current_tarball_number); 1980 if (length_of_file(filelist_name) <= 2) { 1981 log_msg(2, "There are _zero_ files in filelist '%s'", 1982 filelist_name); 1983 log_msg(2, 1984 "This is a bit silly (ask Hugo to fix mondo-makefilelist, please)"); 1985 log_msg(2, 1986 "but it's non-critical. It's cosmetic. Don't worry about it."); 1987 retval = 0; 1988 goto leave_sub; 1989 } 1990 if (count_lines_in_file(filelist_name) <= 0 1991 || length_of_file(tarball_fname) <= 0) { 1992 log_msg(3, "length_of_file(%s) = %ld", tarball_fname, 1993 length_of_file(tarball_fname)); 1994 sprintf(tmp, "Unable to restore fileset #%ld (CD I/O error)", 1995 current_tarball_number); 1996 log_to_screen(tmp); 1997 retval = 1; 1998 goto leave_sub; 1999 } 2000 2001 if (filelist) { 2002 sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", 2003 current_tarball_number); 2004 if ((matches = 2005 save_filelist_entries_in_common(filelist_name, filelist, 2006 filelist_subset_fname, 2007 use_star)) 2008 <= 0) { 2009 sprintf(tmp, "Skipping fileset %ld", current_tarball_number); 2010 log_msg(1, tmp); 2011 } else { 2012 log_msg(3, "Saved fileset %ld's subset to %s", 2013 current_tarball_number, filelist_subset_fname); 2014 } 2015 sprintf(screen_message, "Tarball #%ld --- %ld matches", 2016 current_tarball_number, matches); 2017 log_to_screen(screen_message); 2018 } else { 2019 filelist_subset_fname[0] = '\0'; 2020 } 2021 2022 if (filelist == NULL || matches > 0) { 2023 sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, 2024 MNT_CDROM "/archives", current_tarball_number); 2025 sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", 2026 current_tarball_number); 2027 if (strstr(tarball_fname, ".bz2")) { 2028 strcpy(executable, "bzip2"); 2029 } else if (strstr(tarball_fname, ".lzo")) { 2030 strcpy(executable, "lzop"); 2031 } else { 2032 executable[0] = '\0'; 2033 } 2034 if (executable[0]) { 2035 sprintf(tmp, "which %s > /dev/null 2> /dev/null", executable); 2036 if (run_program_and_log_output(tmp, FALSE)) { 2037 log_to_screen 2038 ("(compare_a_tarball) Compression program not found - oh no!"); 2039 paranoid_MR_finish(1); 2040 } 2041 strcpy(tmp, executable); 2042 sprintf(executable, "-P %s -Z", tmp); 2043 } 2046 2044 #ifdef __FreeBSD__ 2047 2045 #define BUFSIZE 512 … … 2051 2049 2052 2050 // if (strstr(tarball_fname, ".star.")) 2053 if (use_star) 2054 { 2055 sprintf( command, "star -x -force-remove -U " STAR_ACL_SZ " errctl= file=%s", tarball_fname); 2056 if (strstr (tarball_fname, ".bz2")) 2057 { strcat( command, " -bz"); } 2058 } 2059 else 2060 { 2061 if ( filelist_subset_fname[0] != '\0' ) 2062 { 2063 sprintf( command, 2064 "afio -i -M 8m -b %ld -c %ld %s -w %s %s", 2065 TAPE_BLOCK_SIZE, 2066 BUFSIZE, 2067 executable, 2068 filelist_subset_fname, 2069 // files_to_restore_this_time_fname, 2070 tarball_fname); 2071 } 2072 else 2073 { 2074 sprintf( command, 2075 "afio -i -b %ld -c %ld -M 8m %s %s", 2076 TAPE_BLOCK_SIZE, 2077 BUFSIZE, 2078 executable, 2079 tarball_fname); 2080 } 2081 } 2051 if (use_star) { 2052 sprintf(command, 2053 "star -x -force-remove -U " STAR_ACL_SZ 2054 " errctl= file=%s", tarball_fname); 2055 if (strstr(tarball_fname, ".bz2")) { 2056 strcat(command, " -bz"); 2057 } 2058 } else { 2059 if (filelist_subset_fname[0] != '\0') { 2060 sprintf(command, 2061 "afio -i -M 8m -b %ld -c %ld %s -w %s %s", 2062 TAPE_BLOCK_SIZE, 2063 BUFSIZE, executable, filelist_subset_fname, 2064 // files_to_restore_this_time_fname, 2065 tarball_fname); 2066 } else { 2067 sprintf(command, 2068 "afio -i -b %ld -c %ld -M 8m %s %s", 2069 TAPE_BLOCK_SIZE, 2070 BUFSIZE, executable, tarball_fname); 2071 } 2072 } 2082 2073 #undef BUFSIZE 2083 sprintf(command+strlen(command), " 2>> %s >> %s", temp_log, temp_log); 2084 log_msg(1,"command = '%s'", command); 2085 unlink(temp_log); 2086 res = system(command); 2087 if (res) 2088 { 2089 p = strstr(command, "-acl "); 2090 if (p) 2091 { 2092 p[0]=p[1]=p[2]=p[3]=' '; 2093 log_msg(1,"new command = '%s'", command); 2094 res = system(command); 2095 } 2096 } 2097 if (res && length_of_file(temp_log)<5) { res=0; } 2098 2099 log_msg(1, "Setting fattr list %s", xattr_fname); 2100 if (length_of_file(xattr_fname)>0) 2101 { 2102 res=set_fattr_list(filelist_subset_fname, xattr_fname); 2103 if (res) { log_to_screen("Errors occurred while setting extended attributes"); } 2104 else { log_msg(1, "I set xattr OK"); } 2105 retval += res; 2106 } 2107 if (length_of_file(acl_fname)>0) 2108 { 2109 log_msg(1, "Setting acl list %s", acl_fname); 2110 res=set_acl_list(filelist_subset_fname, acl_fname); 2111 if (res) { log_to_screen("Errors occurred while setting access control lists"); } 2112 else { log_msg(1, "I set ACL OK"); } 2113 retval += res; 2114 } 2115 if ( retval ) 2116 { 2117 sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE); 2118 system(command); 2119 log_msg(2, "Errors occurred while processing fileset #%d",current_tarball_number); 2120 } 2121 else 2122 { 2123 log_msg(2, "Fileset #%d processed OK", current_tarball_number); 2124 } 2125 } 2126 if (does_file_exist("/PAUSE")) 2127 { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); } 2128 unlink(filelist_subset_fname); 2129 unlink(xattr_fname); 2130 unlink(acl_fname); 2131 unlink(temp_log); 2132 2133 leave_sub: 2134 paranoid_free(command); paranoid_free(tmp); 2135 paranoid_free(filelist_name); paranoid_free(filelist_subset_fname); 2136 paranoid_free(executable); paranoid_free(temp_log); 2137 paranoid_free(xattr_fname); paranoid_free(acl_fname); 2138 log_msg(5, "Leaving"); 2139 return(retval); 2074 sprintf(command + strlen(command), " 2>> %s >> %s", temp_log, 2075 temp_log); 2076 log_msg(1, "command = '%s'", command); 2077 unlink(temp_log); 2078 res = system(command); 2079 if (res) { 2080 p = strstr(command, "-acl "); 2081 if (p) { 2082 p[0] = p[1] = p[2] = p[3] = ' '; 2083 log_msg(1, "new command = '%s'", command); 2084 res = system(command); 2085 } 2086 } 2087 if (res && length_of_file(temp_log) < 5) { 2088 res = 0; 2089 } 2090 2091 log_msg(1, "Setting fattr list %s", xattr_fname); 2092 if (length_of_file(xattr_fname) > 0) { 2093 res = set_fattr_list(filelist_subset_fname, xattr_fname); 2094 if (res) { 2095 log_to_screen 2096 ("Errors occurred while setting extended attributes"); 2097 } else { 2098 log_msg(1, "I set xattr OK"); 2099 } 2100 retval += res; 2101 } 2102 if (length_of_file(acl_fname) > 0) { 2103 log_msg(1, "Setting acl list %s", acl_fname); 2104 res = set_acl_list(filelist_subset_fname, acl_fname); 2105 if (res) { 2106 log_to_screen 2107 ("Errors occurred while setting access control lists"); 2108 } else { 2109 log_msg(1, "I set ACL OK"); 2110 } 2111 retval += res; 2112 } 2113 if (retval) { 2114 sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE); 2115 system(command); 2116 log_msg(2, "Errors occurred while processing fileset #%d", 2117 current_tarball_number); 2118 } else { 2119 log_msg(2, "Fileset #%d processed OK", current_tarball_number); 2120 } 2121 } 2122 if (does_file_exist("/PAUSE")) { 2123 popup_and_OK 2124 ("Press ENTER to go on. Delete /PAUSE to stop these pauses."); 2125 } 2126 unlink(filelist_subset_fname); 2127 unlink(xattr_fname); 2128 unlink(acl_fname); 2129 unlink(temp_log); 2130 2131 leave_sub: 2132 paranoid_free(command); 2133 paranoid_free(tmp); 2134 paranoid_free(filelist_name); 2135 paranoid_free(filelist_subset_fname); 2136 paranoid_free(executable); 2137 paranoid_free(temp_log); 2138 paranoid_free(xattr_fname); 2139 paranoid_free(acl_fname); 2140 log_msg(5, "Leaving"); 2141 return (retval); 2140 2142 } 2141 2143 … … 2162 2164 int 2163 2165 restore_a_tarball_from_stream(struct s_bkpinfo *bkpinfo, 2164 char *tarball_fname, 2165 long current_tarball_number, 2166 struct s_node*filelist, 2167 long long size, char*xattr_fname, char*acl_fname) 2166 char *tarball_fname, 2167 long current_tarball_number, 2168 struct s_node *filelist, 2169 long long size, char *xattr_fname, 2170 char *acl_fname) 2168 2171 { 2169 2170 2172 int retval = 0; 2173 int res = 0; 2171 2174 2172 2175 /** malloc add ***/ 2173 2174 2175 2176 2177 2178 2179 long matches=0;2180 2181 2182 2183 assert(bkpinfo!=NULL);2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE;2194 sprintf(tmp,2195 "Restoring from fileset #%ld (%ld KB) on %s #%d",current_tarball_number,2196 (long) size>>10,2197 2198 g_current_media_number);2199 log_msg(2, tmp);2200 run_program_and_log_output( "mkdir -p " MNT_RESTORING "/tmp", FALSE);2176 char *tmp; 2177 char *command; 2178 char *afio_fname; 2179 char *filelist_fname; 2180 char *filelist_subset_fname; 2181 char *executable; 2182 long matches = 0; 2183 bool restore_this_fileset = FALSE; 2184 bool use_star; 2185 2186 assert(bkpinfo != NULL); 2187 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 2188 malloc_string(filelist_subset_fname); 2189 malloc_string(filelist_fname); 2190 malloc_string(afio_fname); 2191 malloc_string(executable); 2192 malloc_string(command); 2193 malloc_string(tmp); 2194 filelist_subset_fname[0] = '\0'; 2195 /* to do it with a file... */ 2196 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 2197 sprintf(tmp, 2198 "Restoring from fileset #%ld (%ld KB) on %s #%d", 2199 current_tarball_number, (long) size >> 10, 2200 media_descriptor_string(bkpinfo->backup_media_type), 2201 g_current_media_number); 2202 log_msg(2, tmp); 2203 run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE); 2201 2204 2202 2205 /**************************************************************************** … … 2205 2208 * in afio or someting; oh darn.. OK, use tmpfs :-) * 2206 2209 ****************************************************************************/ 2207 filelist_fname[0] = filelist_subset_fname[0] = '\0'; 2208 sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", current_tarball_number); 2209 sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, current_tarball_number); 2210 sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", bkpinfo->tmpdir, current_tarball_number); 2210 filelist_fname[0] = filelist_subset_fname[0] = '\0'; 2211 sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", 2212 current_tarball_number); 2213 sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, 2214 current_tarball_number); 2215 sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", 2216 bkpinfo->tmpdir, current_tarball_number); 2211 2217 // sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number); 2212 res = read_file_from_stream_to_file( bkpinfo, afio_fname,size ); 2213 if (strstr(tarball_fname, ".star")) { bkpinfo->use_star = TRUE; } 2214 if (res) { log_msg(1, "Warning - error reading afioball from tape"); } 2215 if (bkpinfo->compression_level == 0) 2216 { 2217 executable[0] = '\0'; 2218 } 2219 else 2220 { 2221 if (bkpinfo->use_star) 2222 { strcpy(executable, " -bz"); } 2223 else 2224 { sprintf(executable, "-P %s -Z", bkpinfo->zip_exe); } 2225 } 2226 2227 if (!filelist) // if unconditional restore then restore entire fileset 2228 { 2229 restore_this_fileset = TRUE; 2230 } 2231 else // If restoring selectively then get TOC from tarball 2232 { 2233 if (strstr(tarball_fname, ".star.")) 2234 { 2235 use_star = TRUE; 2236 sprintf( command, "star -t file=%s %s", afio_fname, executable); 2237 } 2238 else 2239 { 2240 use_star = FALSE; 2241 sprintf( command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, 2242 executable, afio_fname); 2243 } 2244 sprintf(command+strlen(command), " > %s 2>> %s", filelist_fname, MONDO_LOGFILE); 2245 log_msg(1, "command = %s", command); 2246 if (system(command)) { log_msg(4, "Warning - error occurred while retrieving TOC"); } 2247 if ((matches=save_filelist_entries_in_common(filelist_fname, filelist, filelist_subset_fname, use_star)) 2248 <= 0 2249 || length_of_file(filelist_subset_fname)<2) 2250 { 2251 if (length_of_file(filelist_subset_fname)<2) 2252 { log_msg(1, "No matches found in fileset %ld", current_tarball_number); } 2253 sprintf(tmp, "Skipping fileset %ld", current_tarball_number); 2254 log_msg(2, tmp); 2255 restore_this_fileset = FALSE; 2256 } 2257 else 2258 { 2259 log_msg(5, "%ld matches. Saved fileset %ld's subset to %s", matches, current_tarball_number, filelist_subset_fname); 2260 restore_this_fileset = TRUE; 2261 } 2262 } 2218 res = read_file_from_stream_to_file(bkpinfo, afio_fname, size); 2219 if (strstr(tarball_fname, ".star")) { 2220 bkpinfo->use_star = TRUE; 2221 } 2222 if (res) { 2223 log_msg(1, "Warning - error reading afioball from tape"); 2224 } 2225 if (bkpinfo->compression_level == 0) { 2226 executable[0] = '\0'; 2227 } else { 2228 if (bkpinfo->use_star) { 2229 strcpy(executable, " -bz"); 2230 } else { 2231 sprintf(executable, "-P %s -Z", bkpinfo->zip_exe); 2232 } 2233 } 2234 2235 if (!filelist) // if unconditional restore then restore entire fileset 2236 { 2237 restore_this_fileset = TRUE; 2238 } else // If restoring selectively then get TOC from tarball 2239 { 2240 if (strstr(tarball_fname, ".star.")) { 2241 use_star = TRUE; 2242 sprintf(command, "star -t file=%s %s", afio_fname, executable); 2243 } else { 2244 use_star = FALSE; 2245 sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, 2246 executable, afio_fname); 2247 } 2248 sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname, 2249 MONDO_LOGFILE); 2250 log_msg(1, "command = %s", command); 2251 if (system(command)) { 2252 log_msg(4, "Warning - error occurred while retrieving TOC"); 2253 } 2254 if ((matches = 2255 save_filelist_entries_in_common(filelist_fname, filelist, 2256 filelist_subset_fname, 2257 use_star)) 2258 <= 0 || length_of_file(filelist_subset_fname) < 2) { 2259 if (length_of_file(filelist_subset_fname) < 2) { 2260 log_msg(1, "No matches found in fileset %ld", 2261 current_tarball_number); 2262 } 2263 sprintf(tmp, "Skipping fileset %ld", current_tarball_number); 2264 log_msg(2, tmp); 2265 restore_this_fileset = FALSE; 2266 } else { 2267 log_msg(5, "%ld matches. Saved fileset %ld's subset to %s", 2268 matches, current_tarball_number, 2269 filelist_subset_fname); 2270 restore_this_fileset = TRUE; 2271 } 2272 } 2263 2273 2264 2274 // Concoct the call to star/afio to restore files 2265 if (strstr(tarball_fname, ".star.")) // star 2266 { 2267 sprintf( command, "star -x file=%s %s", afio_fname, executable); 2268 if (filelist) 2269 { sprintf(command+strlen(command), " list=%s", filelist_subset_fname); } 2270 } 2271 else // afio 2272 { 2273 sprintf( command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, executable); 2274 if (filelist) 2275 { sprintf(command+strlen(command), " -w %s", filelist_subset_fname); } 2276 sprintf(command+strlen(command), " %s", afio_fname); 2277 } 2278 sprintf( command+strlen(command), " 2>> %s", MONDO_LOGFILE); 2275 if (strstr(tarball_fname, ".star.")) // star 2276 { 2277 sprintf(command, "star -x file=%s %s", afio_fname, executable); 2278 if (filelist) { 2279 sprintf(command + strlen(command), " list=%s", 2280 filelist_subset_fname); 2281 } 2282 } else // afio 2283 { 2284 sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, 2285 executable); 2286 if (filelist) { 2287 sprintf(command + strlen(command), " -w %s", 2288 filelist_subset_fname); 2289 } 2290 sprintf(command + strlen(command), " %s", afio_fname); 2291 } 2292 sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE); 2279 2293 2280 2294 // Call if IF there are files to restore (selectively/unconditionally) 2281 if (restore_this_fileset) 2282 { 2283 log_msg(1, "Calling command='%s'", command); 2284 paranoid_system(command); 2285 2286 iamhere("Restoring xattr, acl stuff"); 2287 res=set_fattr_list(filelist_subset_fname, xattr_fname); 2288 if (res) { log_msg(1, "Errors occurred while setting xattr"); } 2289 else { log_msg(1, "I set xattr OK"); } 2290 retval += res; 2291 2292 res=set_acl_list(filelist_subset_fname, acl_fname); 2293 if (res) { log_msg(1, "Errors occurred while setting ACL"); } 2294 else { log_msg(1, "I set ACL OK"); } 2295 retval += res; 2296 2297 } 2298 else 2299 { 2300 log_msg(1, "NOT CALLING '%s'", command); 2301 } 2302 2303 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) 2304 { 2305 log_to_screen("Paused after set %ld", current_tarball_number); 2306 popup_and_OK("Pausing. Press ENTER to continue."); 2307 } 2308 2309 unlink(filelist_subset_fname); 2310 unlink(filelist_fname); 2311 unlink(afio_fname); 2312 2313 paranoid_free(filelist_subset_fname); 2314 paranoid_free(filelist_fname); 2315 paranoid_free(afio_fname); 2316 paranoid_free(command); 2317 paranoid_free(tmp); 2318 return(retval); 2295 if (restore_this_fileset) { 2296 log_msg(1, "Calling command='%s'", command); 2297 paranoid_system(command); 2298 2299 iamhere("Restoring xattr, acl stuff"); 2300 res = set_fattr_list(filelist_subset_fname, xattr_fname); 2301 if (res) { 2302 log_msg(1, "Errors occurred while setting xattr"); 2303 } else { 2304 log_msg(1, "I set xattr OK"); 2305 } 2306 retval += res; 2307 2308 res = set_acl_list(filelist_subset_fname, acl_fname); 2309 if (res) { 2310 log_msg(1, "Errors occurred while setting ACL"); 2311 } else { 2312 log_msg(1, "I set ACL OK"); 2313 } 2314 retval += res; 2315 2316 } else { 2317 log_msg(1, "NOT CALLING '%s'", command); 2318 } 2319 2320 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) { 2321 log_to_screen("Paused after set %ld", current_tarball_number); 2322 popup_and_OK("Pausing. Press ENTER to continue."); 2323 } 2324 2325 unlink(filelist_subset_fname); 2326 unlink(filelist_fname); 2327 unlink(afio_fname); 2328 2329 paranoid_free(filelist_subset_fname); 2330 paranoid_free(filelist_fname); 2331 paranoid_free(afio_fname); 2332 paranoid_free(command); 2333 paranoid_free(tmp); 2334 return (retval); 2319 2335 } 2336 2320 2337 /************************************************************************** 2321 2338 *END_RESTORE_A_TARBALL_FROM_STREAM * … … 2335 2352 */ 2336 2353 int 2337 restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo, struct s_node* filelist) 2354 restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo, 2355 struct s_node *filelist) 2338 2356 { 2339 2340 2341 2357 int retval = 0; 2358 int res; 2359 long noof_biggiefiles, bigfileno = 0, total_slices; 2342 2360 /** malloc **/ 2343 char *tmp; 2344 bool just_changed_cds = FALSE, finished; 2345 char *xattr_fname; 2346 char *acl_fname; 2347 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes 2348 char *pathname_of_last_biggie_restored; 2349 FILE *fbw = NULL; 2350 2351 malloc_string(xattr_fname); 2352 malloc_string(acl_fname); 2353 malloc_string(tmp); 2354 malloc_string(biggies_whose_EXATs_we_should_set); 2355 malloc_string(pathname_of_last_biggie_restored); 2356 assert(bkpinfo!=NULL); 2357 2358 sprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2359 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) 2360 { log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set); } 2361 2362 read_cfg_var( g_mondo_cfg_file, "total-slices", tmp); 2363 total_slices = atol( tmp ); 2364 sprintf(tmp,"Reassembling large files "); 2365 mvaddstr_and_log_it( g_currentY, 0, tmp ); 2366 if (length_of_file(BIGGIELIST) < 6) 2367 { 2368 log_msg(1, "OK, no biggielist; not restoring biggiefiles"); 2369 return(0); 2370 } 2371 noof_biggiefiles = count_lines_in_file(BIGGIELIST); 2372 if ( noof_biggiefiles <= 0 ) 2373 { 2374 log_msg(2, "OK, no biggiefiles in biggielist; not restoring biggiefiles"); 2375 return(0); 2376 } 2377 sprintf( tmp,"OK, there are %ld biggiefiles in the archives",noof_biggiefiles); 2378 log_msg(2, tmp ); 2379 2380 open_progress_form( "Reassembling large files", 2381 "I am now reassembling all the large files." , 2382 "Please wait. This may take some time.", 2383 "", 2384 total_slices); 2385 for( bigfileno = 0, finished = FALSE; !finished;) 2386 { 2387 log_msg( 2, "Thinking about restoring bigfile %ld", bigfileno + 1 ); 2388 if ( !does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, "" ) ) ) 2389 { 2390 log_msg(3, "...but its first slice isn't on this CD. Perhaps this was a selective restore?"); 2391 log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", bigfileno+1, media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2392 log_msg(3, "Slicename would have been %s", slice_fname(bigfileno+1,0,ARCHIVES_PATH,"")); 2393 // I'm not positive 'just_changed_cds' is even necessary... 2394 if (just_changed_cds) 2395 { 2396 just_changed_cds = FALSE; 2397 log_msg(3, "I'll continue to scan this CD for bigfiles to be restored."); 2398 } 2399 else if (does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST")) 2400 { 2401 insist_on_this_cd_number(bkpinfo, ++g_current_media_number); 2402 sprintf(tmp,"Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2403 log_to_screen(tmp); 2404 just_changed_cds = TRUE; 2405 } 2406 else 2407 { 2408 log_msg(2, "There was no bigfile #%ld. That's OK." ,bigfileno+1); 2409 log_msg(2, "I'm going to stop restoring bigfiles now."); 2410 finished = TRUE; 2411 } 2412 } 2413 else 2414 { 2415 just_changed_cds = FALSE; 2416 sprintf(tmp,"Restoring big file %ld",bigfileno + 1); 2417 update_progress_form(tmp); 2418 res = restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist, pathname_of_last_biggie_restored); 2419 iamhere(pathname_of_last_biggie_restored); 2420 if (fbw && pathname_of_last_biggie_restored[0]) 2421 { fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); } 2422 retval += res; 2423 bigfileno++; 2424 2425 } 2426 } 2427 2428 if (fbw) 2429 { 2430 fclose(fbw); 2431 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2432 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2433 if (length_of_file(acl_fname) >0 && find_home_of_exe("setfacl")) 2434 { 2435 set_acl_list (biggies_whose_EXATs_we_should_set, acl_fname); 2436 } 2437 if (length_of_file(xattr_fname)>0 && find_home_of_exe("setfattr")) 2438 { 2439 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname); 2440 } 2441 } 2442 if (does_file_exist("/PAUSE")) 2443 { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); } 2444 close_progress_form(); 2445 if (retval) 2446 { 2447 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2448 } 2449 else 2450 { 2451 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2452 } 2453 paranoid_free(xattr_fname); 2454 paranoid_free(acl_fname); 2455 paranoid_free(tmp); 2456 paranoid_free(biggies_whose_EXATs_we_should_set); 2457 paranoid_free(pathname_of_last_biggie_restored); 2458 return( retval ); 2361 char *tmp; 2362 bool just_changed_cds = FALSE, finished; 2363 char *xattr_fname; 2364 char *acl_fname; 2365 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes 2366 char *pathname_of_last_biggie_restored; 2367 FILE *fbw = NULL; 2368 2369 malloc_string(xattr_fname); 2370 malloc_string(acl_fname); 2371 malloc_string(tmp); 2372 malloc_string(biggies_whose_EXATs_we_should_set); 2373 malloc_string(pathname_of_last_biggie_restored); 2374 assert(bkpinfo != NULL); 2375 2376 sprintf(biggies_whose_EXATs_we_should_set, 2377 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2378 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) { 2379 log_msg(1, "Warning - cannot openout %s", 2380 biggies_whose_EXATs_we_should_set); 2381 } 2382 2383 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp); 2384 total_slices = atol(tmp); 2385 sprintf(tmp, "Reassembling large files "); 2386 mvaddstr_and_log_it(g_currentY, 0, tmp); 2387 if (length_of_file(BIGGIELIST) < 6) { 2388 log_msg(1, "OK, no biggielist; not restoring biggiefiles"); 2389 return (0); 2390 } 2391 noof_biggiefiles = count_lines_in_file(BIGGIELIST); 2392 if (noof_biggiefiles <= 0) { 2393 log_msg(2, 2394 "OK, no biggiefiles in biggielist; not restoring biggiefiles"); 2395 return (0); 2396 } 2397 sprintf(tmp, "OK, there are %ld biggiefiles in the archives", 2398 noof_biggiefiles); 2399 log_msg(2, tmp); 2400 2401 open_progress_form("Reassembling large files", 2402 "I am now reassembling all the large files.", 2403 "Please wait. This may take some time.", 2404 "", total_slices); 2405 for (bigfileno = 0, finished = FALSE; !finished;) { 2406 log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1); 2407 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) { 2408 log_msg(3, 2409 "...but its first slice isn't on this CD. Perhaps this was a selective restore?"); 2410 log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", 2411 bigfileno + 1, 2412 media_descriptor_string(bkpinfo->backup_media_type), 2413 g_current_media_number); 2414 log_msg(3, "Slicename would have been %s", 2415 slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, "")); 2416 // I'm not positive 'just_changed_cds' is even necessary... 2417 if (just_changed_cds) { 2418 just_changed_cds = FALSE; 2419 log_msg(3, 2420 "I'll continue to scan this CD for bigfiles to be restored."); 2421 } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) { 2422 insist_on_this_cd_number(bkpinfo, 2423 ++g_current_media_number); 2424 sprintf(tmp, "Restoring from %s #%d", 2425 media_descriptor_string(bkpinfo-> 2426 backup_media_type), 2427 g_current_media_number); 2428 log_to_screen(tmp); 2429 just_changed_cds = TRUE; 2430 } else { 2431 log_msg(2, "There was no bigfile #%ld. That's OK.", 2432 bigfileno + 1); 2433 log_msg(2, "I'm going to stop restoring bigfiles now."); 2434 finished = TRUE; 2435 } 2436 } else { 2437 just_changed_cds = FALSE; 2438 sprintf(tmp, "Restoring big file %ld", bigfileno + 1); 2439 update_progress_form(tmp); 2440 res = 2441 restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist, 2442 pathname_of_last_biggie_restored); 2443 iamhere(pathname_of_last_biggie_restored); 2444 if (fbw && pathname_of_last_biggie_restored[0]) { 2445 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); 2446 } 2447 retval += res; 2448 bigfileno++; 2449 2450 } 2451 } 2452 2453 if (fbw) { 2454 fclose(fbw); 2455 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2456 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2457 if (length_of_file(acl_fname) > 0 && find_home_of_exe("setfacl")) { 2458 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname); 2459 } 2460 if (length_of_file(xattr_fname) > 0 2461 && find_home_of_exe("setfattr")) { 2462 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname); 2463 } 2464 } 2465 if (does_file_exist("/PAUSE")) { 2466 popup_and_OK 2467 ("Press ENTER to go on. Delete /PAUSE to stop these pauses."); 2468 } 2469 close_progress_form(); 2470 if (retval) { 2471 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2472 } else { 2473 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2474 } 2475 paranoid_free(xattr_fname); 2476 paranoid_free(acl_fname); 2477 paranoid_free(tmp); 2478 paranoid_free(biggies_whose_EXATs_we_should_set); 2479 paranoid_free(pathname_of_last_biggie_restored); 2480 return (retval); 2459 2481 } 2482 2460 2483 /************************************************************************** 2461 2484 *END_RESTORE_ALL_BIGGIFILES_FROM_CD * … … 2475 2498 */ 2476 2499 int 2477 restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo, struct s_node* filelist) 2500 restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo, 2501 struct s_node *filelist) 2478 2502 { 2479 2480 2481 2482 2483 2503 int retval = 0; 2504 int res; 2505 int attempts; 2506 long current_tarball_number = 0; 2507 long max_val; 2484 2508 /**malloc ***/ 2485 char *tmp; 2486 char *tarball_fname; 2487 char *progress_str; 2488 char *comment; 2489 2490 malloc_string(tmp); 2491 malloc_string(tarball_fname); 2492 malloc_string(progress_str); 2493 malloc_string(comment); 2494 2495 assert(bkpinfo!=NULL); 2496 2497 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives"); 2498 log_msg(2, "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER"); 2499 if ( g_current_media_number != 1) 2500 { 2501 log_msg(3, "OK, that's jacked up."); 2502 g_current_media_number = 1; 2503 } 2504 insist_on_this_cd_number( bkpinfo, g_current_media_number); 2505 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2506 max_val = atol(tmp) + 1; 2507 sprintf(progress_str,"Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2508 log_to_screen(progress_str); 2509 open_progress_form("Restoring from archives", 2510 "Restoring data from the archives." , 2511 "Please wait. This may take some time.", 2512 progress_str,max_val); 2513 for(;;) 2514 { 2515 insist_on_this_cd_number(bkpinfo, g_current_media_number); 2516 update_progress_form(progress_str); 2517 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.bz2",current_tarball_number); 2518 if (!does_file_exist(tarball_fname)) 2519 { 2520 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.lzo",current_tarball_number); 2521 } 2522 if (!does_file_exist(tarball_fname)) 2523 { 2524 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.",current_tarball_number); 2525 } 2526 if (!does_file_exist(tarball_fname)) 2527 { 2528 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.star.bz2", current_tarball_number); 2529 } 2530 if (!does_file_exist(tarball_fname)) 2531 { 2532 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.star.", current_tarball_number); 2533 } 2534 if (!does_file_exist(tarball_fname)) 2535 { 2536 if (current_tarball_number == 0) 2537 { 2538 log_to_screen("No tarballs. Strange. Maybe you only backed up freakin' big files?"); 2539 return(0); 2540 } 2541 if (!does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST") || system("find "MNT_CDROM"/archives/slice* > /dev/null 2> /dev/null") == 0 ) 2542 { 2543 break; 2544 } 2545 g_current_media_number++; 2546 sprintf(progress_str,"Restoring from %s #%d",media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2547 log_to_screen(progress_str); 2548 } 2549 else 2550 { 2551 sprintf(progress_str,"Restoring from fileset #%ld on %s #%d", 2552 current_tarball_number, 2553 media_descriptor_string(bkpinfo->backup_media_type), 2554 g_current_media_number); 2555 // log_msg(3, "progress_str = %s", progress_str); 2556 for(res = 999, attempts = 0; attempts < 3 && res != 0; attempts++) 2557 { 2558 res = restore_a_tarball_from_CD(tarball_fname,current_tarball_number, filelist); 2559 } 2560 sprintf(tmp,"%s #%d, fileset #%ld - restore ", 2561 media_descriptor_string(bkpinfo->backup_media_type), 2562 g_current_media_number, 2563 current_tarball_number); 2564 if (res) 2565 { 2566 strcat(tmp,"reported errors"); 2567 } 2568 else if (attempts > 1) 2569 { 2570 strcat(tmp,"succeeded"); 2571 } 2572 else 2573 { 2574 strcat(tmp,"succeeded"); 2575 } 2576 if (attempts > 1) 2577 { 2578 sprintf( tmp + strlen(tmp)," (%d attempts) - review logs",attempts); 2579 } 2580 strcpy(comment, tmp); 2581 if (attempts > 1) 2582 { 2583 log_to_screen(comment); 2584 } 2585 2586 retval += res; 2587 current_tarball_number++; 2588 g_current_progress++; 2589 } 2590 } 2591 close_progress_form(); 2592 if (retval) 2593 { 2594 mvaddstr_and_log_it(g_currentY++,74,"Errors."); 2595 } 2596 else 2597 { 2598 mvaddstr_and_log_it(g_currentY++,74,"Done."); 2599 } 2600 paranoid_free(tmp); 2601 paranoid_free(tarball_fname); 2602 paranoid_free(progress_str); 2603 paranoid_free(comment); 2604 2605 return(retval); 2509 char *tmp; 2510 char *tarball_fname; 2511 char *progress_str; 2512 char *comment; 2513 2514 malloc_string(tmp); 2515 malloc_string(tarball_fname); 2516 malloc_string(progress_str); 2517 malloc_string(comment); 2518 2519 assert(bkpinfo != NULL); 2520 2521 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives"); 2522 log_msg(2, 2523 "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER"); 2524 if (g_current_media_number != 1) { 2525 log_msg(3, "OK, that's jacked up."); 2526 g_current_media_number = 1; 2527 } 2528 insist_on_this_cd_number(bkpinfo, g_current_media_number); 2529 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2530 max_val = atol(tmp) + 1; 2531 sprintf(progress_str, "Restoring from %s #%d", 2532 media_descriptor_string(bkpinfo->backup_media_type), 2533 g_current_media_number); 2534 log_to_screen(progress_str); 2535 open_progress_form("Restoring from archives", 2536 "Restoring data from the archives.", 2537 "Please wait. This may take some time.", 2538 progress_str, max_val); 2539 for (;;) { 2540 insist_on_this_cd_number(bkpinfo, g_current_media_number); 2541 update_progress_form(progress_str); 2542 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2", 2543 current_tarball_number); 2544 if (!does_file_exist(tarball_fname)) { 2545 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo", 2546 current_tarball_number); 2547 } 2548 if (!does_file_exist(tarball_fname)) { 2549 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.", 2550 current_tarball_number); 2551 } 2552 if (!does_file_exist(tarball_fname)) { 2553 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2", 2554 current_tarball_number); 2555 } 2556 if (!does_file_exist(tarball_fname)) { 2557 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.", 2558 current_tarball_number); 2559 } 2560 if (!does_file_exist(tarball_fname)) { 2561 if (current_tarball_number == 0) { 2562 log_to_screen 2563 ("No tarballs. Strange. Maybe you only backed up freakin' big files?"); 2564 return (0); 2565 } 2566 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST") 2567 || system("find " MNT_CDROM 2568 "/archives/slice* > /dev/null 2> /dev/null") == 2569 0) { 2570 break; 2571 } 2572 g_current_media_number++; 2573 sprintf(progress_str, "Restoring from %s #%d", 2574 media_descriptor_string(bkpinfo->backup_media_type), 2575 g_current_media_number); 2576 log_to_screen(progress_str); 2577 } else { 2578 sprintf(progress_str, "Restoring from fileset #%ld on %s #%d", 2579 current_tarball_number, 2580 media_descriptor_string(bkpinfo->backup_media_type), 2581 g_current_media_number); 2582 // log_msg(3, "progress_str = %s", progress_str); 2583 for (res = 999, attempts = 0; attempts < 3 && res != 0; 2584 attempts++) { 2585 res = 2586 restore_a_tarball_from_CD(tarball_fname, 2587 current_tarball_number, 2588 filelist); 2589 } 2590 sprintf(tmp, "%s #%d, fileset #%ld - restore ", 2591 media_descriptor_string(bkpinfo->backup_media_type), 2592 g_current_media_number, current_tarball_number); 2593 if (res) { 2594 strcat(tmp, "reported errors"); 2595 } else if (attempts > 1) { 2596 strcat(tmp, "succeeded"); 2597 } else { 2598 strcat(tmp, "succeeded"); 2599 } 2600 if (attempts > 1) { 2601 sprintf(tmp + strlen(tmp), " (%d attempts) - review logs", 2602 attempts); 2603 } 2604 strcpy(comment, tmp); 2605 if (attempts > 1) { 2606 log_to_screen(comment); 2607 } 2608 2609 retval += res; 2610 current_tarball_number++; 2611 g_current_progress++; 2612 } 2613 } 2614 close_progress_form(); 2615 if (retval) { 2616 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2617 } else { 2618 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2619 } 2620 paranoid_free(tmp); 2621 paranoid_free(tarball_fname); 2622 paranoid_free(progress_str); 2623 paranoid_free(comment); 2624 2625 return (retval); 2606 2626 } 2607 2627 … … 2620 2640 */ 2621 2641 int 2622 restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo, struct s_node*filelist) 2642 restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo, 2643 struct s_node *filelist) 2623 2644 { 2624 2625 2626 2627 2628 2629 2630 2645 long noof_biggiefiles; 2646 long current_bigfile_number = 0; 2647 long total_slices; 2648 2649 int retval = 0; 2650 int res = 0; 2651 int ctrl_chr; 2631 2652 2632 2653 /** malloc add ****/ 2633 char *tmp; 2634 char *biggie_fname; 2635 char *biggie_cksum; 2636 char *xattr_fname; 2637 char *acl_fname; 2638 char *p; 2639 char *pathname_of_last_biggie_restored; 2640 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes 2641 long long biggie_size; 2642 FILE *fbw = NULL; 2643 2644 malloc_string(tmp); 2645 malloc_string(biggie_fname); 2646 malloc_string(biggie_cksum); 2647 malloc_string(xattr_fname); 2648 malloc_string(acl_fname); 2649 malloc_string(biggies_whose_EXATs_we_should_set); 2650 malloc_string(pathname_of_last_biggie_restored); 2651 assert(bkpinfo!=NULL); 2652 2653 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp); 2654 2655 total_slices = atol(tmp); 2656 sprintf(tmp, "Reassembling large files "); 2657 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2658 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2659 mvaddstr_and_log_it( g_currentY, 0, tmp ); 2660 sprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2661 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) 2662 { log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set); } 2663 2654 char *tmp; 2655 char *biggie_fname; 2656 char *biggie_cksum; 2657 char *xattr_fname; 2658 char *acl_fname; 2659 char *p; 2660 char *pathname_of_last_biggie_restored; 2661 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes 2662 long long biggie_size; 2663 FILE *fbw = NULL; 2664 2665 malloc_string(tmp); 2666 malloc_string(biggie_fname); 2667 malloc_string(biggie_cksum); 2668 malloc_string(xattr_fname); 2669 malloc_string(acl_fname); 2670 malloc_string(biggies_whose_EXATs_we_should_set); 2671 malloc_string(pathname_of_last_biggie_restored); 2672 assert(bkpinfo != NULL); 2673 2674 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp); 2675 2676 total_slices = atol(tmp); 2677 sprintf(tmp, "Reassembling large files "); 2678 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2679 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2680 mvaddstr_and_log_it(g_currentY, 0, tmp); 2681 sprintf(biggies_whose_EXATs_we_should_set, 2682 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2683 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) { 2684 log_msg(1, "Warning - cannot openout %s", 2685 biggies_whose_EXATs_we_should_set); 2686 } 2664 2687 // get xattr and acl files if they're there 2665 res = read_header_block_from_stream( &biggie_size, biggie_fname, &ctrl_chr); 2666 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) 2667 { 2668 res = read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname, &ctrl_chr, xattr_fname, acl_fname); 2669 } 2670 2671 noof_biggiefiles = atol( biggie_fname ); 2672 sprintf( tmp, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles ); 2673 log_msg(2, tmp ); 2674 open_progress_form( "Reassembling large files", 2675 "I am now reassembling all the large files." , 2676 "Please wait. This may take some time.", 2677 "", 2678 total_slices); 2679 2680 for( res = read_header_block_from_stream( &biggie_size, biggie_fname, &ctrl_chr); ctrl_chr!=BLK_STOP_BIGGIEFILES; res=read_header_block_from_stream(&biggie_size, biggie_fname, &ctrl_chr)) 2681 { 2682 if (ctrl_chr != BLK_START_A_NORMBIGGIE && ctrl_chr != BLK_START_A_PIHBIGGIE) 2683 { 2684 wrong_marker(BLK_START_A_NORMBIGGIE,ctrl_chr); 2685 } 2686 p = strrchr(biggie_fname,'/'); 2687 if (!p) 2688 { 2689 p = biggie_fname; 2690 } 2691 else 2692 { 2693 p++; 2694 } 2695 sprintf(tmp,"Restoring big file %ld (%lld K)",current_bigfile_number+1, biggie_size/1024); 2696 update_progress_form(tmp); 2697 res = restore_a_biggiefile_from_stream(bkpinfo,biggie_fname, 2698 current_bigfile_number, 2699 biggie_cksum, 2700 biggie_size, 2701 filelist, ctrl_chr, 2702 pathname_of_last_biggie_restored); 2703 log_msg(1, "I believe I have restored %s", pathname_of_last_biggie_restored); 2704 if (fbw && pathname_of_last_biggie_restored[0]) 2705 { fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); } 2706 retval += res; 2707 current_bigfile_number++; 2708 2709 } 2710 if (current_bigfile_number != noof_biggiefiles && noof_biggiefiles != 0 ) 2711 { 2712 sprintf( tmp, 2713 "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",current_bigfile_number, 2714 noof_biggiefiles); 2715 } 2716 else 2717 { 2718 sprintf( tmp,"%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", 2719 noof_biggiefiles, 2720 current_bigfile_number); 2721 } 2722 log_msg(1, tmp); 2723 2724 if (fbw) 2725 { 2726 fclose(fbw); 2727 if (length_of_file(biggies_whose_EXATs_we_should_set) >2) 2728 { 2729 iamhere("Setting biggie-EXATs"); 2730 if (length_of_file(acl_fname) >0) 2731 { 2732 log_msg(1, "set_acl_list(%s,%s)", biggies_whose_EXATs_we_should_set, acl_fname); 2733 set_acl_list (biggies_whose_EXATs_we_should_set, acl_fname); 2734 } 2735 if (length_of_file(xattr_fname)>0) 2736 { 2737 log_msg(1, "set_fattr_List(%s,%s)", biggies_whose_EXATs_we_should_set, xattr_fname); 2738 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname); 2739 } 2740 } 2741 else 2742 { 2743 iamhere("No biggiefiles selected. So, no biggie-EXATs to set."); 2744 } 2745 } 2746 if (does_file_exist("/PAUSE")) 2747 { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); } 2748 2749 close_progress_form(); 2750 if (retval) 2751 { 2752 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2753 } 2754 else 2755 { 2756 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2757 } 2758 paranoid_free(biggies_whose_EXATs_we_should_set); 2759 paranoid_free(pathname_of_last_biggie_restored); 2760 paranoid_free(biggie_fname); 2761 paranoid_free(biggie_cksum); 2762 paranoid_free(xattr_fname); 2763 paranoid_free(acl_fname); 2764 paranoid_free(tmp); 2765 return(retval); 2688 res = 2689 read_header_block_from_stream(&biggie_size, biggie_fname, 2690 &ctrl_chr); 2691 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 2692 res = 2693 read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname, 2694 &ctrl_chr, xattr_fname, acl_fname); 2695 } 2696 2697 noof_biggiefiles = atol(biggie_fname); 2698 sprintf(tmp, "OK, there are %ld biggiefiles in the archives", 2699 noof_biggiefiles); 2700 log_msg(2, tmp); 2701 open_progress_form("Reassembling large files", 2702 "I am now reassembling all the large files.", 2703 "Please wait. This may take some time.", 2704 "", total_slices); 2705 2706 for (res = 2707 read_header_block_from_stream(&biggie_size, biggie_fname, 2708 &ctrl_chr); 2709 ctrl_chr != BLK_STOP_BIGGIEFILES; 2710 res = 2711 read_header_block_from_stream(&biggie_size, biggie_fname, 2712 &ctrl_chr)) { 2713 if (ctrl_chr != BLK_START_A_NORMBIGGIE 2714 && ctrl_chr != BLK_START_A_PIHBIGGIE) { 2715 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr); 2716 } 2717 p = strrchr(biggie_fname, '/'); 2718 if (!p) { 2719 p = biggie_fname; 2720 } else { 2721 p++; 2722 } 2723 sprintf(tmp, "Restoring big file %ld (%lld K)", 2724 current_bigfile_number + 1, biggie_size / 1024); 2725 update_progress_form(tmp); 2726 res = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname, 2727 current_bigfile_number, 2728 biggie_cksum, 2729 biggie_size, 2730 filelist, ctrl_chr, 2731 pathname_of_last_biggie_restored); 2732 log_msg(1, "I believe I have restored %s", 2733 pathname_of_last_biggie_restored); 2734 if (fbw && pathname_of_last_biggie_restored[0]) { 2735 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); 2736 } 2737 retval += res; 2738 current_bigfile_number++; 2739 2740 } 2741 if (current_bigfile_number != noof_biggiefiles 2742 && noof_biggiefiles != 0) { 2743 sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n", 2744 current_bigfile_number, noof_biggiefiles); 2745 } else { 2746 sprintf(tmp, 2747 "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", 2748 noof_biggiefiles, current_bigfile_number); 2749 } 2750 log_msg(1, tmp); 2751 2752 if (fbw) { 2753 fclose(fbw); 2754 if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) { 2755 iamhere("Setting biggie-EXATs"); 2756 if (length_of_file(acl_fname) > 0) { 2757 log_msg(1, "set_acl_list(%s,%s)", 2758 biggies_whose_EXATs_we_should_set, acl_fname); 2759 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname); 2760 } 2761 if (length_of_file(xattr_fname) > 0) { 2762 log_msg(1, "set_fattr_List(%s,%s)", 2763 biggies_whose_EXATs_we_should_set, xattr_fname); 2764 set_fattr_list(biggies_whose_EXATs_we_should_set, 2765 xattr_fname); 2766 } 2767 } else { 2768 iamhere 2769 ("No biggiefiles selected. So, no biggie-EXATs to set."); 2770 } 2771 } 2772 if (does_file_exist("/PAUSE")) { 2773 popup_and_OK 2774 ("Press ENTER to go on. Delete /PAUSE to stop these pauses."); 2775 } 2776 2777 close_progress_form(); 2778 if (retval) { 2779 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2780 } else { 2781 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2782 } 2783 paranoid_free(biggies_whose_EXATs_we_should_set); 2784 paranoid_free(pathname_of_last_biggie_restored); 2785 paranoid_free(biggie_fname); 2786 paranoid_free(biggie_cksum); 2787 paranoid_free(xattr_fname); 2788 paranoid_free(acl_fname); 2789 paranoid_free(tmp); 2790 return (retval); 2766 2791 } 2792 2767 2793 /************************************************************************** 2768 2794 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM * … … 2785 2811 */ 2786 2812 int 2787 restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo, struct s_node *filelist) 2813 restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo, 2814 struct s_node *filelist) 2788 2815 { 2789 2790 2791 2792 2793 long max_val /*, total_noof_files */;2816 int retval = 0; 2817 int res; 2818 long current_afioball_number = 0; 2819 int ctrl_chr; 2820 long max_val /*, total_noof_files */ ; 2794 2821 2795 2822 /** malloc **/ 2796 char *tmp; 2797 char *progress_str; 2798 char *tmp_fname; 2799 char *xattr_fname; 2800 char *acl_fname; 2801 2802 long long tmp_size; 2803 2804 malloc_string(tmp); 2805 malloc_string(progress_str); 2806 malloc_string(tmp_fname); 2807 assert(bkpinfo!=NULL); 2808 malloc_string(xattr_fname); 2809 malloc_string(acl_fname); 2810 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives"); 2811 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2812 max_val = atol(tmp) + 1; 2813 2814 chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */ 2815 2816 run_program_and_log_output("pwd", 5); 2817 2818 sprintf(progress_str,"Restoring from media #%d",g_current_media_number); 2819 log_to_screen(progress_str); 2820 open_progress_form("Restoring from archives", 2821 "Restoring data from the archives." , 2822 "Please wait. This may take some time.", 2823 progress_str,max_val); 2824 2825 log_msg(3, "hey"); 2826 2827 res = read_header_block_from_stream( &tmp_size, tmp_fname, &ctrl_chr); 2828 if (res) 2829 { 2830 log_msg(2, "Warning - error reading afioball from tape"); 2831 } 2832 retval += res; 2833 if ( ctrl_chr != BLK_START_AFIOBALLS) 2834 { 2835 wrong_marker(BLK_START_AFIOBALLS,ctrl_chr); 2836 } 2837 log_msg(2, "ho"); 2838 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2839 while(ctrl_chr!=BLK_STOP_AFIOBALLS) 2840 { 2841 update_progress_form(progress_str); 2842 sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number); 2843 sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number); 2844 unlink(xattr_fname); 2845 unlink(acl_fname); 2846 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) 2847 { 2848 iamhere("Reading EXAT files from tape"); 2849 res = read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname, &ctrl_chr, xattr_fname, acl_fname); 2850 } 2851 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) 2852 { wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); } 2853 sprintf(tmp, 2854 "Restoring from fileset #%ld (name=%s, size=%ld K)", 2855 current_afioball_number, 2856 tmp_fname, 2857 (long) tmp_size>>10); 2858 res = restore_a_tarball_from_stream(bkpinfo,tmp_fname,current_afioball_number,filelist,tmp_size, xattr_fname, acl_fname); 2859 retval += res; 2860 if ( res ) 2861 { 2862 sprintf(tmp,"Fileset %ld - errors occurred",current_afioball_number); 2863 log_to_screen(tmp); 2864 } 2865 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2866 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) 2867 { 2868 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE,ctrl_chr); 2869 } 2870 2871 current_afioball_number++; 2872 g_current_progress++; 2873 sprintf(progress_str,"Restoring from fileset #%ld on %s #%d",current_afioball_number, media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2874 res=read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2875 unlink(xattr_fname); 2876 unlink(acl_fname); 2877 } // next 2878 log_msg(1, "All done with afioballs"); 2879 close_progress_form(); 2880 if (retval) 2881 { 2882 mvaddstr_and_log_it(g_currentY++,74,"Errors."); } 2883 else 2884 { 2885 mvaddstr_and_log_it(g_currentY++,74,"Done."); } 2886 paranoid_free(tmp); 2887 paranoid_free(progress_str); 2888 paranoid_free(tmp_fname); 2889 paranoid_free(xattr_fname); 2890 paranoid_free(acl_fname); 2891 return(retval); 2823 char *tmp; 2824 char *progress_str; 2825 char *tmp_fname; 2826 char *xattr_fname; 2827 char *acl_fname; 2828 2829 long long tmp_size; 2830 2831 malloc_string(tmp); 2832 malloc_string(progress_str); 2833 malloc_string(tmp_fname); 2834 assert(bkpinfo != NULL); 2835 malloc_string(xattr_fname); 2836 malloc_string(acl_fname); 2837 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives"); 2838 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2839 max_val = atol(tmp) + 1; 2840 2841 chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */ 2842 2843 run_program_and_log_output("pwd", 5); 2844 2845 sprintf(progress_str, "Restoring from media #%d", 2846 g_current_media_number); 2847 log_to_screen(progress_str); 2848 open_progress_form("Restoring from archives", 2849 "Restoring data from the archives.", 2850 "Please wait. This may take some time.", 2851 progress_str, max_val); 2852 2853 log_msg(3, "hey"); 2854 2855 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2856 if (res) { 2857 log_msg(2, "Warning - error reading afioball from tape"); 2858 } 2859 retval += res; 2860 if (ctrl_chr != BLK_START_AFIOBALLS) { 2861 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr); 2862 } 2863 log_msg(2, "ho"); 2864 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2865 while (ctrl_chr != BLK_STOP_AFIOBALLS) { 2866 update_progress_form(progress_str); 2867 sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, 2868 current_afioball_number); 2869 sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, 2870 current_afioball_number); 2871 unlink(xattr_fname); 2872 unlink(acl_fname); 2873 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 2874 iamhere("Reading EXAT files from tape"); 2875 res = 2876 read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname, 2877 &ctrl_chr, xattr_fname, 2878 acl_fname); 2879 } 2880 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 2881 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 2882 } 2883 sprintf(tmp, 2884 "Restoring from fileset #%ld (name=%s, size=%ld K)", 2885 current_afioball_number, tmp_fname, (long) tmp_size >> 10); 2886 res = 2887 restore_a_tarball_from_stream(bkpinfo, tmp_fname, 2888 current_afioball_number, 2889 filelist, tmp_size, xattr_fname, 2890 acl_fname); 2891 retval += res; 2892 if (res) { 2893 sprintf(tmp, "Fileset %ld - errors occurred", 2894 current_afioball_number); 2895 log_to_screen(tmp); 2896 } 2897 res = 2898 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2899 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { 2900 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 2901 } 2902 2903 current_afioball_number++; 2904 g_current_progress++; 2905 sprintf(progress_str, "Restoring from fileset #%ld on %s #%d", 2906 current_afioball_number, 2907 media_descriptor_string(bkpinfo->backup_media_type), 2908 g_current_media_number); 2909 res = 2910 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2911 unlink(xattr_fname); 2912 unlink(acl_fname); 2913 } // next 2914 log_msg(1, "All done with afioballs"); 2915 close_progress_form(); 2916 if (retval) { 2917 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2918 } else { 2919 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2920 } 2921 paranoid_free(tmp); 2922 paranoid_free(progress_str); 2923 paranoid_free(tmp_fname); 2924 paranoid_free(xattr_fname); 2925 paranoid_free(acl_fname); 2926 return (retval); 2892 2927 } 2928 2893 2929 /************************************************************************** 2894 2930 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM * … … 2906 2942 * @ingroup restoreGroup 2907 2943 */ 2908 int 2909 restore_everything(struct s_bkpinfo*bkpinfo, 2910 struct s_node *filelist) 2944 int restore_everything(struct s_bkpinfo *bkpinfo, struct s_node *filelist) 2911 2945 { 2912 2913 2946 int resA; 2947 int resB; 2914 2948 2915 2949 /** mallco ***/ 2916 char *cwd; 2917 char *newpath; 2918 char *tmp; 2919 assert(bkpinfo!=NULL); 2920 2921 malloc_string(cwd); 2922 malloc_string(newpath); 2923 malloc_string(tmp); 2924 log_msg(2, "restore_everything() --- starting"); 2925 g_current_media_number = 1; 2926 getcwd(cwd, MAX_STR_LEN - 1); 2927 sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path); 2928 run_program_and_log_output(tmp, FALSE); 2929 log_msg(1, "Changing dir to %s", bkpinfo->restore_path); 2930 chdir(bkpinfo->restore_path); 2931 getcwd(newpath,MAX_STR_LEN-1); 2932 log_msg(1, "path is now %s", newpath); 2933 log_msg(1, "restoring everything"); 2934 if (!find_home_of_exe("petris") && !g_text_mode) 2935 { 2936 newtDrawRootText(0, g_noof_rows-2, "Press ALT-<left cursor> twice to play Petris :-) "); 2937 newtRefresh(); 2938 } 2939 mvaddstr_and_log_it (g_currentY, 0, "Preparing to read your archives"); 2940 if ( IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type ) ) 2941 { 2942 mount_cdrom( bkpinfo ); 2943 mvaddstr_and_log_it ( g_currentY++, 0, "Restoring OS and data from streaming media"); 2944 if (bkpinfo->backup_media_type == cdstream) 2945 { 2946 openin_cdstream( bkpinfo ); 2947 } 2948 else 2949 { 2950 assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device); 2951 openin_tape(bkpinfo); 2952 } 2953 resA = restore_all_tarballs_from_stream(bkpinfo, filelist); 2954 resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist); 2955 if (bkpinfo->backup_media_type == cdstream) 2956 { 2957 closein_cdstream(bkpinfo); 2958 } 2959 else 2960 { 2961 closein_tape(bkpinfo); 2962 } 2963 } 2964 else 2965 { 2966 mvaddstr_and_log_it (g_currentY++, 0, "Restoring OS and data from CD "); 2967 mount_cdrom(bkpinfo); 2968 resA = restore_all_tarballs_from_CD(bkpinfo, filelist); 2969 resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist); 2970 } 2971 chdir(cwd); 2972 if ( resA + resB ) 2973 { 2974 log_to_screen("Errors occurred while data was being restored."); 2975 } 2976 if ( length_of_file("/etc/raidtab") > 0 ) 2977 { 2978 log_msg(2, "Copying local raidtab to restored filesystem"); 2979 run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING "/etc/raidtab", FALSE); 2980 } 2981 kill_petris(); 2982 log_msg(2, "restore_everything() --- leaving"); 2983 paranoid_free(cwd); 2984 paranoid_free(newpath); 2985 paranoid_free(tmp); 2986 return(resA+resB); 2950 char *cwd; 2951 char *newpath; 2952 char *tmp; 2953 assert(bkpinfo != NULL); 2954 2955 malloc_string(cwd); 2956 malloc_string(newpath); 2957 malloc_string(tmp); 2958 log_msg(2, "restore_everything() --- starting"); 2959 g_current_media_number = 1; 2960 getcwd(cwd, MAX_STR_LEN - 1); 2961 sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path); 2962 run_program_and_log_output(tmp, FALSE); 2963 log_msg(1, "Changing dir to %s", bkpinfo->restore_path); 2964 chdir(bkpinfo->restore_path); 2965 getcwd(newpath, MAX_STR_LEN - 1); 2966 log_msg(1, "path is now %s", newpath); 2967 log_msg(1, "restoring everything"); 2968 if (!find_home_of_exe("petris") && !g_text_mode) { 2969 newtDrawRootText(0, g_noof_rows - 2, 2970 "Press ALT-<left cursor> twice to play Petris :-) "); 2971 newtRefresh(); 2972 } 2973 mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives"); 2974 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 2975 mount_cdrom(bkpinfo); 2976 mvaddstr_and_log_it(g_currentY++, 0, 2977 "Restoring OS and data from streaming media"); 2978 if (bkpinfo->backup_media_type == cdstream) { 2979 openin_cdstream(bkpinfo); 2980 } else { 2981 assert_string_is_neither_NULL_nor_zerolength(bkpinfo-> 2982 media_device); 2983 openin_tape(bkpinfo); 2984 } 2985 resA = restore_all_tarballs_from_stream(bkpinfo, filelist); 2986 resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist); 2987 if (bkpinfo->backup_media_type == cdstream) { 2988 closein_cdstream(bkpinfo); 2989 } else { 2990 closein_tape(bkpinfo); 2991 } 2992 } else { 2993 mvaddstr_and_log_it(g_currentY++, 0, 2994 "Restoring OS and data from CD "); 2995 mount_cdrom(bkpinfo); 2996 resA = restore_all_tarballs_from_CD(bkpinfo, filelist); 2997 resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist); 2998 } 2999 chdir(cwd); 3000 if (resA + resB) { 3001 log_to_screen("Errors occurred while data was being restored."); 3002 } 3003 if (length_of_file("/etc/raidtab") > 0) { 3004 log_msg(2, "Copying local raidtab to restored filesystem"); 3005 run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING 3006 "/etc/raidtab", FALSE); 3007 } 3008 kill_petris(); 3009 log_msg(2, "restore_everything() --- leaving"); 3010 paranoid_free(cwd); 3011 paranoid_free(newpath); 3012 paranoid_free(tmp); 3013 return (resA + resB); 2987 3014 } 2988 3015 … … 2997 3024 */ 2998 3025 int 2999 restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo, 3000 char *monitas_device,3001 char *restore_this_directory,3002 char *restore_here)3003 3026 restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo, 3027 char *monitas_device, 3028 char *restore_this_directory, 3029 char *restore_here) 3030 /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */ 3004 3031 { 3005 3006 3007 3008 3009 3010 3032 FILE *fout; 3033 int retval = 0; 3034 int i; 3035 int j; 3036 struct mountlist_itself the_mountlist; 3037 static struct raidlist_itself the_raidlist; 3011 3038 /** malloc **/ 3012 char tmp[ MAX_STR_LEN + 1 ]; 3013 char command[ MAX_STR_LEN + 1 ]; 3014 char datablock[ 256 * 1024 ]; 3015 char datadisks_fname[ MAX_STR_LEN + 1 ]; 3016 long k; 3017 long length; 3018 long long llt; 3019 struct s_node *filelist = NULL; 3020 assert(bkpinfo!=NULL); 3021 assert_string_is_neither_NULL_nor_zerolength(monitas_device); 3022 assert(restore_this_directory != NULL); 3023 assert(restore_here != NULL); 3024 3025 sprintf(tmp, "restore_here = '%s'", restore_here); 3026 3027 log_msg(2, tmp); 3028 3029 log_msg(2, "restore_live_from_monitas_server() - starting"); 3030 unlink("/tmp/mountlist.txt"); unlink("/tmp/filelist.full"); 3031 unlink("/tmp/biggielist.txt"); 3032 if ( restore_here[0] == '\0' ) 3033 { 3034 strcpy(bkpinfo->restore_path, MNT_RESTORING); 3035 } 3036 else 3037 { 3038 strcpy(bkpinfo->restore_path, restore_here); 3039 } 3040 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI"); 3041 sprintf(tmp, "FYI - data will be restored to %s", bkpinfo->restore_path); 3042 log_msg(3, tmp); 3043 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI"); 3044 sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d", (int)(random()%32768)); 3045 chdir(bkpinfo->tmpdir); 3046 3047 sprintf(command, "cat %s", monitas_device); 3048 g_tape_stream=popen(command, "r"); // for compatibility with openin_tape() 3049 if (!(fout = fopen(datadisks_fname, "w"))) { log_OS_error(datadisks_fname); return(1); } 3050 for (i = 0; i < 32; i++) 3051 { 3052 for (j = 0; j < 4; j++) 3053 { 3054 for( length = k = 0; length < 256 * 1024; length += k) 3055 { 3056 k = fread( datablock + length, 1, 256 * 1024 - length, g_tape_stream); 3057 } 3058 fwrite (datablock, 1, length, fout); 3059 g_tape_posK += length; 3060 } 3061 } 3062 paranoid_fclose(fout); 3063 sprintf( command, 3064 "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt", 3065 datadisks_fname); 3066 run_program_and_log_output(command, 4); 3067 read_header_block_from_stream (&llt, tmp, &i); 3068 read_header_block_from_stream (&llt, tmp, &i); 3069 3070 unlink(datadisks_fname); 3071 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 3072 retval = load_mountlist( &the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo strcpy(bkpinfo->media_device, monitas_device); 3073 3074 3075 load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME ); 3076 iamhere("FIXME"); 3077 fatal_error("This will fail"); 3078 sprintf( command, 3079 "cat %s | grep -x \"%s.*\" > %s", 3080 g_filelist_full, 3081 restore_this_directory, 3082 g_filelist_full); 3083 if (system(command)) 3084 { 3085 retval++; 3086 log_to_screen("Error(s) occurred while processing filelist and wildcard"); 3087 } 3088 iamhere("FIXME"); 3089 fatal_error("This will fail"); 3090 sprintf(command, 3091 "cat %s | grep -x \"%s.*\" > %s", 3092 g_biggielist_txt, 3093 restore_this_directory, 3094 g_biggielist_txt); 3095 if (system(command)) 3096 { 3097 log_msg(1, "Error(s) occurred while processing biggielist and wildcard"); 3098 } 3099 sprintf(command, "touch %s", g_biggielist_txt); 3100 run_program_and_log_output(command, FALSE); 3039 char tmp[MAX_STR_LEN + 1]; 3040 char command[MAX_STR_LEN + 1]; 3041 char datablock[256 * 1024]; 3042 char datadisks_fname[MAX_STR_LEN + 1]; 3043 long k; 3044 long length; 3045 long long llt; 3046 struct s_node *filelist = NULL; 3047 assert(bkpinfo != NULL); 3048 assert_string_is_neither_NULL_nor_zerolength(monitas_device); 3049 assert(restore_this_directory != NULL); 3050 assert(restore_here != NULL); 3051 3052 sprintf(tmp, "restore_here = '%s'", restore_here); 3053 3054 log_msg(2, tmp); 3055 3056 log_msg(2, "restore_live_from_monitas_server() - starting"); 3057 unlink("/tmp/mountlist.txt"); 3058 unlink("/tmp/filelist.full"); 3059 unlink("/tmp/biggielist.txt"); 3060 if (restore_here[0] == '\0') { 3061 strcpy(bkpinfo->restore_path, MNT_RESTORING); 3062 } else { 3063 strcpy(bkpinfo->restore_path, restore_here); 3064 } 3065 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI"); 3066 sprintf(tmp, "FYI - data will be restored to %s", 3067 bkpinfo->restore_path); 3068 log_msg(3, tmp); 3069 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI"); 3070 sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d", 3071 (int) (random() % 32768)); 3072 chdir(bkpinfo->tmpdir); 3073 3074 sprintf(command, "cat %s", monitas_device); 3075 g_tape_stream = popen(command, "r"); // for compatibility with openin_tape() 3076 if (!(fout = fopen(datadisks_fname, "w"))) { 3077 log_OS_error(datadisks_fname); 3078 return (1); 3079 } 3080 for (i = 0; i < 32; i++) { 3081 for (j = 0; j < 4; j++) { 3082 for (length = k = 0; length < 256 * 1024; length += k) { 3083 k = fread(datablock + length, 1, 256 * 1024 - length, 3084 g_tape_stream); 3085 } 3086 fwrite(datablock, 1, length, fout); 3087 g_tape_posK += length; 3088 } 3089 } 3090 paranoid_fclose(fout); 3091 sprintf(command, 3092 "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt", 3093 datadisks_fname); 3094 run_program_and_log_output(command, 4); 3095 read_header_block_from_stream(&llt, tmp, &i); 3096 read_header_block_from_stream(&llt, tmp, &i); 3097 3098 unlink(datadisks_fname); 3099 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 3100 retval = load_mountlist(&the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo strcpy(bkpinfo->media_device, monitas_device); 3101 3102 3103 load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME); 3104 iamhere("FIXME"); 3105 fatal_error("This will fail"); 3106 sprintf(command, 3107 "cat %s | grep -x \"%s.*\" > %s", 3108 g_filelist_full, restore_this_directory, g_filelist_full); 3109 if (system(command)) { 3110 retval++; 3111 log_to_screen 3112 ("Error(s) occurred while processing filelist and wildcard"); 3113 } 3114 iamhere("FIXME"); 3115 fatal_error("This will fail"); 3116 sprintf(command, 3117 "cat %s | grep -x \"%s.*\" > %s", 3118 g_biggielist_txt, restore_this_directory, g_biggielist_txt); 3119 if (system(command)) { 3120 log_msg(1, 3121 "Error(s) occurred while processing biggielist and wildcard"); 3122 } 3123 sprintf(command, "touch %s", g_biggielist_txt); 3124 run_program_and_log_output(command, FALSE); 3101 3125 // filelist = load_filelist(g_filelist_restthese); // FIXME --- this probably doesn't work because it doesn't include the biggiefiles 3102 3103 3104 3105 return(retval);3126 retval += restore_everything(bkpinfo, filelist); 3127 free_filelist(filelist); 3128 log_msg(2, "--------End of restore_live_from_monitas_server--------"); 3129 return (retval); 3106 3130 } 3131 3107 3132 /************************************************************************** 3108 3133 *END_RESTORE_LIVE_FROM_MONITAS_SERVER * … … 3112 3137 3113 3138 3114 extern void wait_until_software_raids_are_prepped(char *, int);3139 extern void wait_until_software_raids_are_prepped(char *, int); 3115 3140 3116 3141 … … 3123 3148 void welcome_to_mondorestore() 3124 3149 { 3125 log_msg(0, "-------------- Mondo Restore v%s -------------", VERSION); 3126 log_msg(0, "DON'T PANIC! Mondorestore logs almost everything, so please " ); 3127 log_msg(0, "don't break out in a cold sweat just because you see a few " ); 3128 log_msg(0, "error messages in the log. Read them; analyze them; see if " ); 3129 log_msg(0, "they are significant; above all, verify your backups! Please" ); 3130 log_msg(0, "attach a compressed copy of this log to any e-mail you send " ); 3131 log_msg(0, "to the Mondo mailing list when you are seeking technical " ); 3132 log_msg(0, "support. Without it, we can't help you. - Hugo" ); 3133 log_msg(0, "------------------------------------------------------------" ); 3134 log_msg(0, "BTW, despite (or perhaps because of) the wealth of messages," ); 3135 log_msg(0, "some users are inclined to stop reading this log. If Mondo " ); 3136 log_msg(0, "stopped for some reason, chances are it's detailed here. " ); 3137 log_msg(0, "More than likely there's a message at the very end of this " ); 3138 log_msg(0, "log that will tell you what is wrong. Please read it! " ); 3139 log_msg(0, "------------------------------------------------------------"); 3150 log_msg(0, "-------------- Mondo Restore v%s -------------", VERSION); 3151 log_msg(0, 3152 "DON'T PANIC! Mondorestore logs almost everything, so please "); 3153 log_msg(0, 3154 "don't break out in a cold sweat just because you see a few "); 3155 log_msg(0, 3156 "error messages in the log. Read them; analyze them; see if "); 3157 log_msg(0, 3158 "they are significant; above all, verify your backups! Please"); 3159 log_msg(0, 3160 "attach a compressed copy of this log to any e-mail you send "); 3161 log_msg(0, 3162 "to the Mondo mailing list when you are seeking technical "); 3163 log_msg(0, 3164 "support. Without it, we can't help you. - Hugo"); 3165 log_msg(0, 3166 "------------------------------------------------------------"); 3167 log_msg(0, 3168 "BTW, despite (or perhaps because of) the wealth of messages,"); 3169 log_msg(0, 3170 "some users are inclined to stop reading this log. If Mondo "); 3171 log_msg(0, 3172 "stopped for some reason, chances are it's detailed here. "); 3173 log_msg(0, 3174 "More than likely there's a message at the very end of this "); 3175 log_msg(0, 3176 "log that will tell you what is wrong. Please read it! "); 3177 log_msg(0, 3178 "------------------------------------------------------------"); 3140 3179 } 3141 3180 … … 3146 3185 * What did you think it did, anyway? :-) 3147 3186 */ 3148 int 3149 main(int argc, char*argv[]) 3187 int main(int argc, char *argv[]) 3150 3188 { 3151 FILE*fin;3152 FILE*fout;3153 3154 3189 FILE *fin; 3190 FILE *fout; 3191 int retval = 0; 3192 int res; 3155 3193 // int c; 3156 3194 char *tmp; 3157 3195 3158 3196 #ifndef VERSION … … 3160 3198 #endif 3161 3199 3162 struct mountlist_itself*mountlist;3163 struct raidlist_itself*raidlist;3164 struct s_bkpinfo*bkpinfo;3165 3166 3200 struct mountlist_itself *mountlist; 3201 struct raidlist_itself *raidlist; 3202 struct s_bkpinfo *bkpinfo; 3203 struct s_node *filelist; 3204 char *a, *b; 3167 3205 3168 3206 /************************************************************************** … … 3171 3209 * * 3172 3210 **************************************************************************/ 3173 if (getuid () != 0) 3174 { 3175 fprintf (stderr, "Please run as root.\r\n"); 3176 exit (127); 3177 } 3178 3179 g_loglevel = DEFAULT_MR_LOGLEVEL; 3180 malloc_string(tmp); 3181 3211 if (getuid() != 0) { 3212 fprintf(stderr, "Please run as root.\r\n"); 3213 exit(127); 3214 } 3215 3216 g_loglevel = DEFAULT_MR_LOGLEVEL; 3217 malloc_string(tmp); 3218 3182 3219 /* Configure global variables */ 3183 3220 #ifdef __FreeBSD__ 3184 if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "textonly")) 3221 if (strstr 3222 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"), 3223 "textonly")) 3185 3224 #else 3186 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "textonly")) 3225 if (strstr 3226 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 3227 "textonly")) 3187 3228 #endif 3188 { g_text_mode = TRUE; log_msg(1, "TEXTONLY MODE"); } 3189 else 3190 { g_text_mode = FALSE; } // newt :-) 3191 if ( ! ( bkpinfo = g_bkpinfo_DONTUSETHIS = malloc( sizeof(struct s_bkpinfo)))) 3192 { fatal_error( "Cannot malloc bkpinfo" ); } 3193 if ( ! ( mountlist = malloc (sizeof(struct mountlist_itself)))) 3194 { fatal_error ("Cannot malloc mountlist" ); } 3195 if ( ! ( raidlist = malloc (sizeof(struct raidlist_itself)))) 3196 { fatal_error ("Cannot malloc raidlist" ); } 3197 3198 malloc_libmondo_global_strings(); 3199 3200 strcpy( g_mondo_home, call_program_and_get_last_line_of_output("which mondorestore") ); 3201 sprintf(g_tmpfs_mountpt, "/tmp/tmpfs"); 3202 make_hole_for_dir(g_tmpfs_mountpt); 3203 g_current_media_number = 1; // precaution 3204 3205 run_program_and_log_output ("mkdir -p " MNT_CDROM, FALSE); 3206 run_program_and_log_output ("mkdir -p /mnt/floppy", FALSE); 3207 3208 malloc_string(tmp); 3209 malloc_string(a); 3210 malloc_string(b); 3211 setup_MR_global_filenames( bkpinfo ); // malloc() and set globals, using bkpinfo->tmpdir etc. 3212 reset_bkpinfo( bkpinfo ); 3213 bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type 3214 bkpinfo->restore_data = TRUE; // Well, yeah :-) 3215 if (am_I_in_disaster_recovery_mode()) 3216 { run_program_and_log_output("mount / -o remount,rw",2); } // for b0rken distros 3217 g_main_pid = getpid(); 3218 srandom( (int)(time(NULL)) ); 3219 register_pid( getpid(), "mondo" ); 3220 set_signals(TRUE); 3221 g_kernel_version = get_kernel_version(); 3222 3223 log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname); 3224 if (strlen(g_mountlist_fname) < 3) 3225 { fatal_error("Serious error in malloc()'ing. Could be a bug in your glibc."); } 3226 mkdir(MNT_CDROM, 0x770); 3227 3229 { 3230 g_text_mode = TRUE; 3231 log_msg(1, "TEXTONLY MODE"); 3232 } else { 3233 g_text_mode = FALSE; 3234 } // newt :-) 3235 if (! 3236 (bkpinfo = g_bkpinfo_DONTUSETHIS = 3237 malloc(sizeof(struct s_bkpinfo)))) { 3238 fatal_error("Cannot malloc bkpinfo"); 3239 } 3240 if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) { 3241 fatal_error("Cannot malloc mountlist"); 3242 } 3243 if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) { 3244 fatal_error("Cannot malloc raidlist"); 3245 } 3246 3247 malloc_libmondo_global_strings(); 3248 3249 strcpy(g_mondo_home, 3250 call_program_and_get_last_line_of_output("which mondorestore")); 3251 sprintf(g_tmpfs_mountpt, "/tmp/tmpfs"); 3252 make_hole_for_dir(g_tmpfs_mountpt); 3253 g_current_media_number = 1; // precaution 3254 3255 run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE); 3256 run_program_and_log_output("mkdir -p /mnt/floppy", FALSE); 3257 3258 malloc_string(tmp); 3259 malloc_string(a); 3260 malloc_string(b); 3261 setup_MR_global_filenames(bkpinfo); // malloc() and set globals, using bkpinfo->tmpdir etc. 3262 reset_bkpinfo(bkpinfo); 3263 bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type 3264 bkpinfo->restore_data = TRUE; // Well, yeah :-) 3265 if (am_I_in_disaster_recovery_mode()) { 3266 run_program_and_log_output("mount / -o remount,rw", 2); 3267 } // for b0rken distros 3268 g_main_pid = getpid(); 3269 srandom((int) (time(NULL))); 3270 register_pid(getpid(), "mondo"); 3271 set_signals(TRUE); 3272 g_kernel_version = get_kernel_version(); 3273 3274 log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname); 3275 if (strlen(g_mountlist_fname) < 3) { 3276 fatal_error 3277 ("Serious error in malloc()'ing. Could be a bug in your glibc."); 3278 } 3279 mkdir(MNT_CDROM, 0x770); 3280 3228 3281 /* Backup original mountlist.txt */ 3229 sprintf(tmp, "%s.orig", g_mountlist_fname);3230 if (!does_file_exist(g_mountlist_fname)) 3231 { 3232 log_msg(2, "%ld: Warning - g_mountlist_fname (%s) does not exist yet", __LINE__, g_mountlist_fname); 3233 } 3234 else if ( !does_file_exist(tmp) ) 3235 { 3236 sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,g_mountlist_fname);3237 3238 3282 sprintf(tmp, "%s.orig", g_mountlist_fname); 3283 if (!does_file_exist(g_mountlist_fname)) { 3284 log_msg(2, 3285 "%ld: Warning - g_mountlist_fname (%s) does not exist yet", 3286 __LINE__, g_mountlist_fname); 3287 } else if (!does_file_exist(tmp)) { 3288 sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname, 3289 g_mountlist_fname); 3290 run_program_and_log_output(tmp, FALSE); 3291 } 3239 3292 3240 3293 /* Init directories */ 3241 make_hole_for_dir(bkpinfo->tmpdir); 3242 sprintf( tmp, "mkdir -p %s", bkpinfo->tmpdir ); 3243 run_program_and_log_output( tmp, FALSE ); 3244 make_hole_for_dir( "/var/log"); 3245 make_hole_for_dir( "/tmp/tmpfs"); /* just in case... */ 3246 run_program_and_log_output( "umount "MNT_CDROM, FALSE ); 3247 run_program_and_log_output( "ln -sf /var/log/mondo-archive.log /tmp/mondo-restore.log", FALSE ); 3248 3249 run_program_and_log_output( "rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE); 3294 make_hole_for_dir(bkpinfo->tmpdir); 3295 sprintf(tmp, "mkdir -p %s", bkpinfo->tmpdir); 3296 run_program_and_log_output(tmp, FALSE); 3297 make_hole_for_dir("/var/log"); 3298 make_hole_for_dir("/tmp/tmpfs"); /* just in case... */ 3299 run_program_and_log_output("umount " MNT_CDROM, FALSE); 3300 run_program_and_log_output 3301 ("ln -sf /var/log/mondo-archive.log /tmp/mondo-restore.log", 3302 FALSE); 3303 3304 run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE); 3250 3305 3251 3306 /* Init GUI */ 3252 malloc_libmondo_global_strings(); 3253 setup_newt_stuff(); /* call newtInit and setup screen log */ 3254 welcome_to_mondorestore(); 3255 if ( bkpinfo->disaster_recovery ) 3256 { log_msg(1, "I am in disaster recovery mode" ); } 3257 else 3258 { log_msg(1, "I am in normal, live mode" ); } 3259 3260 iamhere("what time is it"); 3307 malloc_libmondo_global_strings(); 3308 setup_newt_stuff(); /* call newtInit and setup screen log */ 3309 welcome_to_mondorestore(); 3310 if (bkpinfo->disaster_recovery) { 3311 log_msg(1, "I am in disaster recovery mode"); 3312 } else { 3313 log_msg(1, "I am in normal, live mode"); 3314 } 3315 3316 iamhere("what time is it"); 3261 3317 3262 3318 /* Process command-line parameters */ 3263 if (argc == 2 && strcmp( argv[1], "--edit-mountlist" ) == 0 ) 3264 { 3319 if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) { 3265 3320 #ifdef __FreeBSD__ 3266 system("mv -f /tmp/raidconf.txt /etc/raidtab");3267 if (!does_file_exist("/etc/raidtab"))3268 system("vinum printconfig > /etc/raidtab");3321 system("mv -f /tmp/raidconf.txt /etc/raidtab"); 3322 if (!does_file_exist("/etc/raidtab")) 3323 system("vinum printconfig > /etc/raidtab"); 3269 3324 #endif 3270 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3271 if (!does_file_exist(g_mountlist_fname)) { strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); } 3272 res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist); 3325 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3326 if (!does_file_exist(g_mountlist_fname)) { 3327 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3328 } 3329 res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist); 3273 3330 #ifdef __FreeBSD__ 3274 system("mv -f /etc/raidtab /tmp/raidconf.txt");3331 system("mv -f /etc/raidtab /tmp/raidconf.txt"); 3275 3332 #endif 3276 paranoid_MR_finish(res); 3277 } 3278 3279 g_loglevel = DEFAULT_MR_LOGLEVEL; 3280 if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) 3281 { 3282 fout = fopen("/tmp/out.txt", "w"); 3283 fput_string_one_char_at_a_time(stderr, argv[2]); 3284 finish(0); 3285 } 3286 3287 if (argc == 3 && strcmp( argv[1], "--gendf" ) == 0 ) 3288 { 3289 make_grub_install_scriptlet(argv[2]); 3290 finish(0); 3291 } 3292 3293 if (argc >= 2 && strcmp(argv[1], "--pih" ) == 0 ) 3294 { 3295 if (system("mount | grep cdrom 2> /dev/null > /dev/null")) 3296 { system("mount "MNT_CDROM); } 3297 bkpinfo->compression_level = 1; 3298 g_current_media_number = 2; 3299 strcpy(bkpinfo->restore_path, "/tmp/TESTING"); 3300 bkpinfo->backup_media_type = dvd; 3301 open_progress_form( "Reassembling /dev/hda1", 3302 "Shark is a bit of a silly person." , 3303 "Please wait. This may take some time.", 3304 "", 3305 1999); 3306 system("rm -Rf /tmp/*pih*"); 3307 3308 restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp); 3309 } 3310 3311 if (argc == 5 && strcmp( argv[1], "--common") == 0 ) 3312 { 3313 g_loglevel = 6; 3314 filelist = load_filelist(argv[2]); 3315 if (!filelist) { fatal_error("Failed to load filelist"); } 3316 toggle_node_selection (filelist, FALSE); 3317 toggle_all_root_dirs_on (filelist); 3318 toggle_path_selection (filelist, "/usr/share", TRUE); 3333 paranoid_MR_finish(res); 3334 } 3335 3336 g_loglevel = DEFAULT_MR_LOGLEVEL; 3337 if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) { 3338 fout = fopen("/tmp/out.txt", "w"); 3339 fput_string_one_char_at_a_time(stderr, argv[2]); 3340 finish(0); 3341 } 3342 3343 if (argc == 3 && strcmp(argv[1], "--gendf") == 0) { 3344 make_grub_install_scriptlet(argv[2]); 3345 finish(0); 3346 } 3347 3348 if (argc >= 2 && strcmp(argv[1], "--pih") == 0) { 3349 if (system("mount | grep cdrom 2> /dev/null > /dev/null")) { 3350 system("mount " MNT_CDROM); 3351 } 3352 bkpinfo->compression_level = 1; 3353 g_current_media_number = 2; 3354 strcpy(bkpinfo->restore_path, "/tmp/TESTING"); 3355 bkpinfo->backup_media_type = dvd; 3356 open_progress_form("Reassembling /dev/hda1", 3357 "Shark is a bit of a silly person.", 3358 "Please wait. This may take some time.", 3359 "", 1999); 3360 system("rm -Rf /tmp/*pih*"); 3361 3362 restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp); 3363 } 3364 3365 if (argc == 5 && strcmp(argv[1], "--common") == 0) { 3366 g_loglevel = 6; 3367 filelist = load_filelist(argv[2]); 3368 if (!filelist) { 3369 fatal_error("Failed to load filelist"); 3370 } 3371 toggle_node_selection(filelist, FALSE); 3372 toggle_all_root_dirs_on(filelist); 3373 toggle_path_selection(filelist, "/usr/share", TRUE); 3319 3374 // show_filelist(filelist); 3320 3375 save_filelist(filelist, "/tmp/out.txt"); 3321 3376 // finish(0); 3322 3377 // toggle_path_selection (filelist, "/root/stuff", TRUE); 3323 strcpy(a, argv[3]); 3324 strcpy(b, argv[4]); 3325 3326 res = save_filelist_entries_in_common( 3327 a, filelist, b, FALSE); 3328 free_filelist(filelist); 3329 printf("res = %d", res); 3330 finish(0); 3331 } 3332 3333 if (argc == 3 && strcmp( argv[1], "--popuplist" ) == 0 ) 3334 { 3335 popup_changelist_from_file( argv[2] ); 3336 paranoid_MR_finish(0); 3337 } 3338 3339 if (argc == 5 && strcmp( argv[1], "--copy" ) == 0 ) 3340 { 3341 log_msg(1, "SCORE"); 3342 g_loglevel = 10; 3343 if (strstr(argv[2], "save")) 3344 { 3345 log_msg(1, "Saving from %s to %s", argv[3], argv[4]); 3346 fin = fopen(argv[3], "r"); 3347 fout = fopen(argv[4], "w"); 3348 copy_from_src_to_dest(fin, fout, 'w'); 3349 fclose(fin); 3350 fin = fopen(argv[3], "r"); 3351 copy_from_src_to_dest(fin, fout, 'w'); 3352 fclose(fout); 3353 fclose(fin); 3354 } 3355 else if (strstr(argv[2], "restore")) 3356 { 3357 fout = fopen(argv[3], "w"); 3358 fin = fopen(argv[4], "r"); 3359 copy_from_src_to_dest(fout, fin, 'r'); 3360 fclose(fin); 3361 fin = fopen(argv[4], "r"); 3362 copy_from_src_to_dest(fout, fin, 'r'); 3363 fclose(fout); 3364 fclose(fin); 3365 } 3366 else 3367 { fatal_error("Unknown additional param"); } 3368 finish(0); 3369 } 3370 3371 if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) 3372 { 3373 wait_until_software_raids_are_prepped(argv[2], 100); 3374 finish(0); 3375 } 3376 3377 if (argc == 4 && strcmp(argv[1], "--mdconv") == 0) 3378 { 3379 finish(create_raidtab_from_mdstat(argv[2], argv[3])); 3380 } 3381 3382 3383 if ( argc == 2 && strcmp( argv[1],"--live-grub" ) == 0 ) 3384 { 3385 retval = run_grub( FALSE, "/dev/hda" ); 3386 if ( retval ) 3387 { 3388 log_to_screen("Failed to write Master Boot Record"); 3389 } 3390 paranoid_MR_finish(0); 3391 } 3392 if (argc == 3 && strcmp( argv[1], "--paa" ) == 0 ) 3393 { 3394 g_current_media_number = atoi(argv[2]); 3395 pause_and_ask_for_cdr(5, NULL); 3396 paranoid_MR_finish(0); 3397 } 3398 else if ( !bkpinfo->disaster_recovery ) 3399 { // live! 3400 if (argc!=1) 3401 { 3402 popup_and_OK("Live mode doesn't support command-line parameters yet."); 3403 paranoid_MR_finish(1); 3404 // return(1); 3405 } 3406 log_msg (1, "I am in normal, live mode."); 3407 log_msg (2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname); 3408 mount_boot_if_necessary(); /* for Gentoo users */ 3409 log_msg (2, "Still here."); 3410 if ( argc>1 && strcmp( argv[argc-1], "--live-from-cd" ) == 0 ) 3411 { g_restoring_live_from_cd = TRUE; } 3412 if ( argc == 5 && strcmp(argv[1], "--monitas-live" ) == 0 ) 3413 { 3414 retval = 3415 restore_live_from_monitas_server( bkpinfo, 3416 argv[2], 3417 argv[3], 3418 argv[4] ); 3419 } 3420 else 3421 { 3422 log_msg(2, "Calling restore_to_live_filesystem()"); 3423 retval = restore_to_live_filesystem( bkpinfo ); 3424 } 3425 log_msg(2, "Still here. Yay."); 3426 if (strlen(bkpinfo->tmpdir) > 0) 3427 { 3428 sprintf( tmp, "rm -Rf %s/*", bkpinfo->tmpdir ); 3429 run_program_and_log_output ( tmp, FALSE ); 3430 } 3431 unmount_boot_if_necessary(); /* for Gentoo users */ 3432 paranoid_MR_finish( retval ); 3433 } 3434 else 3435 { 3378 strcpy(a, argv[3]); 3379 strcpy(b, argv[4]); 3380 3381 res = save_filelist_entries_in_common(a, filelist, b, FALSE); 3382 free_filelist(filelist); 3383 printf("res = %d", res); 3384 finish(0); 3385 } 3386 3387 if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) { 3388 popup_changelist_from_file(argv[2]); 3389 paranoid_MR_finish(0); 3390 } 3391 3392 if (argc == 5 && strcmp(argv[1], "--copy") == 0) { 3393 log_msg(1, "SCORE"); 3394 g_loglevel = 10; 3395 if (strstr(argv[2], "save")) { 3396 log_msg(1, "Saving from %s to %s", argv[3], argv[4]); 3397 fin = fopen(argv[3], "r"); 3398 fout = fopen(argv[4], "w"); 3399 copy_from_src_to_dest(fin, fout, 'w'); 3400 fclose(fin); 3401 fin = fopen(argv[3], "r"); 3402 copy_from_src_to_dest(fin, fout, 'w'); 3403 fclose(fout); 3404 fclose(fin); 3405 } else if (strstr(argv[2], "restore")) { 3406 fout = fopen(argv[3], "w"); 3407 fin = fopen(argv[4], "r"); 3408 copy_from_src_to_dest(fout, fin, 'r'); 3409 fclose(fin); 3410 fin = fopen(argv[4], "r"); 3411 copy_from_src_to_dest(fout, fin, 'r'); 3412 fclose(fout); 3413 fclose(fin); 3414 } else { 3415 fatal_error("Unknown additional param"); 3416 } 3417 finish(0); 3418 } 3419 3420 if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) { 3421 wait_until_software_raids_are_prepped(argv[2], 100); 3422 finish(0); 3423 } 3424 3425 if (argc == 4 && strcmp(argv[1], "--mdconv") == 0) { 3426 finish(create_raidtab_from_mdstat(argv[2], argv[3])); 3427 } 3428 3429 3430 if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) { 3431 retval = run_grub(FALSE, "/dev/hda"); 3432 if (retval) { 3433 log_to_screen("Failed to write Master Boot Record"); 3434 } 3435 paranoid_MR_finish(0); 3436 } 3437 if (argc == 3 && strcmp(argv[1], "--paa") == 0) { 3438 g_current_media_number = atoi(argv[2]); 3439 pause_and_ask_for_cdr(5, NULL); 3440 paranoid_MR_finish(0); 3441 } else if (!bkpinfo->disaster_recovery) { // live! 3442 if (argc != 1) { 3443 popup_and_OK 3444 ("Live mode doesn't support command-line parameters yet."); 3445 paranoid_MR_finish(1); 3446 // return(1); 3447 } 3448 log_msg(1, "I am in normal, live mode."); 3449 log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname); 3450 mount_boot_if_necessary(); /* for Gentoo users */ 3451 log_msg(2, "Still here."); 3452 if (argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) { 3453 g_restoring_live_from_cd = TRUE; 3454 } 3455 if (argc == 5 && strcmp(argv[1], "--monitas-live") == 0) { 3456 retval = 3457 restore_live_from_monitas_server(bkpinfo, 3458 argv[2], 3459 argv[3], argv[4]); 3460 } else { 3461 log_msg(2, "Calling restore_to_live_filesystem()"); 3462 retval = restore_to_live_filesystem(bkpinfo); 3463 } 3464 log_msg(2, "Still here. Yay."); 3465 if (strlen(bkpinfo->tmpdir) > 0) { 3466 sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir); 3467 run_program_and_log_output(tmp, FALSE); 3468 } 3469 unmount_boot_if_necessary(); /* for Gentoo users */ 3470 paranoid_MR_finish(retval); 3471 } else { 3436 3472 /* Disaster recovery mode (must be) */ 3437 log_msg(1, "I must be in disaster recovery mode."); 3438 log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname ); 3439 if (argc == 3 && strcmp(argv[1], "--monitas-memorex" ) == 0 ) 3440 { 3441 log_to_screen( "Uh, that hasn't been implemented yet." ); 3442 paranoid_MR_finish( 1 ); 3443 } 3444 3445 iamhere("About to call load_mountlist and load_raidtab"); 3446 strcpy( bkpinfo->restore_path, MNT_RESTORING ); 3447 read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo ); 3448 retval = load_mountlist( mountlist, g_mountlist_fname ); 3449 retval += load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3450 iamhere("Returned from calling load_mountlist and load_raidtab successfully"); 3451 3452 if (argc>1 && (strcmp( argv[1], "--compare" ) == 0 || strcmp( argv[1], "--nuke" ) == 0 )) 3453 { 3454 if (bkpinfo->backup_media_type == nfs && !is_this_device_mounted(bkpinfo->nfs_mount)) 3455 { 3456 log_msg(1, "Mounting nfs dir"); 3457 sprintf(bkpinfo->isodir, "/tmp/isodir"); 3458 run_program_and_log_output("mkdir -p /tmp/isodir", 5); 3459 sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir", bkpinfo->nfs_mount); 3460 run_program_and_log_output(tmp, 1); 3461 } 3462 } 3463 3464 3465 if ( retval ) 3466 { 3467 log_to_screen( "Warning - load_raidtab_into_raidlist returned an error" ); 3468 } 3469 3470 3471 log_msg(1, "Send in the clowns."); 3472 3473 if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) 3474 { 3475 log_msg(0, "Partitioning only."); 3476 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3477 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3478 load_mountlist( mountlist, g_mountlist_fname ); 3479 res = partition_everything(mountlist); 3480 finish(res); 3481 } 3482 3483 if (argc == 2 && strcmp(argv[1], "--format-only") == 0) 3484 { 3485 log_msg(0, "Formatting only."); 3486 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3487 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3488 load_mountlist( mountlist, g_mountlist_fname ); 3489 res = format_everything(mountlist, FALSE); 3490 finish(res); 3491 } 3492 3493 if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) 3494 { 3495 log_msg(0, "Stopping LVM and RAID"); 3496 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3497 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3498 load_mountlist( mountlist, g_mountlist_fname ); 3499 res = do_my_funky_lvm_stuff(TRUE, FALSE); 3500 res += stop_all_raid_devices(mountlist); 3501 finish(res); 3502 } 3503 3504 if (argc == 2 && strcmp( argv[1], "--nuke" ) == 0 ) 3505 { 3506 iamhere("nuking"); 3507 retval += nuke_mode( bkpinfo, mountlist, raidlist); 3508 } 3509 else if (argc == 2 && strcmp( argv[1], "--interactive" ) == 0 ) 3510 { 3511 iamhere("catchall"); 3512 retval += catchall_mode( bkpinfo, mountlist,raidlist ); 3513 } 3514 else if (argc == 2 && strcmp( argv[1], "--compare" ) == 0 ) 3515 { 3516 iamhere("compare"); 3517 retval += compare_mode( bkpinfo, mountlist, raidlist ); 3518 } 3519 else if (argc == 2 && strcmp( argv[1], "--iso" ) == 0 ) 3520 { 3521 iamhere("iso"); 3522 retval = iso_mode( bkpinfo, mountlist, raidlist, FALSE ); 3523 } 3524 else if ( argc == 2 && strcmp( argv[1],"--mbr" ) == 0 ) 3525 { 3526 iamhere("mbr"); 3527 retval = mount_all_devices( mountlist, TRUE ); 3528 if ( !retval ) 3529 { 3530 retval += run_boot_loader( FALSE ); 3531 retval += unmount_all_devices( mountlist ); 3532 } 3533 if ( retval ) 3534 { 3535 log_to_screen("Failed to write Master Boot Record"); 3536 } 3537 } 3538 else if ( argc == 2 && strcmp( argv[1],"--isonuke") ==0 ) 3539 { 3540 iamhere("isonuke"); 3541 retval = iso_mode( bkpinfo, 3542 mountlist, 3543 raidlist, 3544 TRUE ); 3545 } 3546 else if ( argc != 1 ) 3547 { 3548 log_to_screen( "Invalid paremeters" ); 3549 paranoid_MR_finish( 1 ); 3550 } 3551 else 3552 { 3553 iamhere("catchall (no mode specified in command-line call"); 3554 retval += catchall_mode( bkpinfo, mountlist, raidlist); 3555 } 3556 } 3557 3558 /* clean up at the end */ 3559 if (retval) 3560 { 3561 if (does_file_exist("/tmp/changed.files")) 3562 { 3563 log_to_screen( "See /tmp/changed.files for list of files that have changed." ); 3564 } 3565 mvaddstr_and_log_it ( g_currentY++, 3566 0, 3567 "Run complete. Errors were reported. Please review the logfile." ); 3568 } 3569 else 3570 { 3571 if (IS_THIS_A_STREAMING_BACKUP ( bkpinfo->backup_media_type ) ) 3572 { 3573 mvaddstr_and_log_it( g_currentY++, 3574 0, 3575 "Run complete. Please remove floppy/CD/media and reboot." ); 3576 } 3577 else 3578 { 3579 run_program_and_log_output ( "sync", FALSE ); 3580 if ( is_this_device_mounted( MNT_CDROM ) ) 3581 { 3582 res = run_program_and_log_output( "umount "MNT_CDROM, FALSE ); 3583 } 3584 else 3585 { 3586 res = 0; 3587 } 3588 3589 if ( !bkpinfo->please_dont_eject) 3590 { 3591 res = eject_device("/dev/cdrom"); 3473 log_msg(1, "I must be in disaster recovery mode."); 3474 log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname); 3475 if (argc == 3 && strcmp(argv[1], "--monitas-memorex") == 0) { 3476 log_to_screen("Uh, that hasn't been implemented yet."); 3477 paranoid_MR_finish(1); 3478 } 3479 3480 iamhere("About to call load_mountlist and load_raidtab"); 3481 strcpy(bkpinfo->restore_path, MNT_RESTORING); 3482 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 3483 retval = load_mountlist(mountlist, g_mountlist_fname); 3484 retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3485 iamhere 3486 ("Returned from calling load_mountlist and load_raidtab successfully"); 3487 3488 if (argc > 1 3489 && (strcmp(argv[1], "--compare") == 0 3490 || strcmp(argv[1], "--nuke") == 0)) { 3491 if (bkpinfo->backup_media_type == nfs 3492 && !is_this_device_mounted(bkpinfo->nfs_mount)) { 3493 log_msg(1, "Mounting nfs dir"); 3494 sprintf(bkpinfo->isodir, "/tmp/isodir"); 3495 run_program_and_log_output("mkdir -p /tmp/isodir", 5); 3496 sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir", 3497 bkpinfo->nfs_mount); 3498 run_program_and_log_output(tmp, 1); 3499 } 3500 } 3501 3502 3503 if (retval) { 3504 log_to_screen 3505 ("Warning - load_raidtab_into_raidlist returned an error"); 3506 } 3507 3508 3509 log_msg(1, "Send in the clowns."); 3510 3511 if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) { 3512 log_msg(0, "Partitioning only."); 3513 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3514 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3515 load_mountlist(mountlist, g_mountlist_fname); 3516 res = partition_everything(mountlist); 3517 finish(res); 3518 } 3519 3520 if (argc == 2 && strcmp(argv[1], "--format-only") == 0) { 3521 log_msg(0, "Formatting only."); 3522 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3523 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3524 load_mountlist(mountlist, g_mountlist_fname); 3525 res = format_everything(mountlist, FALSE); 3526 finish(res); 3527 } 3528 3529 if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) { 3530 log_msg(0, "Stopping LVM and RAID"); 3531 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3532 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3533 load_mountlist(mountlist, g_mountlist_fname); 3534 res = do_my_funky_lvm_stuff(TRUE, FALSE); 3535 res += stop_all_raid_devices(mountlist); 3536 finish(res); 3537 } 3538 3539 if (argc == 2 && strcmp(argv[1], "--nuke") == 0) { 3540 iamhere("nuking"); 3541 retval += nuke_mode(bkpinfo, mountlist, raidlist); 3542 } else if (argc == 2 && strcmp(argv[1], "--interactive") == 0) { 3543 iamhere("catchall"); 3544 retval += catchall_mode(bkpinfo, mountlist, raidlist); 3545 } else if (argc == 2 && strcmp(argv[1], "--compare") == 0) { 3546 iamhere("compare"); 3547 retval += compare_mode(bkpinfo, mountlist, raidlist); 3548 } else if (argc == 2 && strcmp(argv[1], "--iso") == 0) { 3549 iamhere("iso"); 3550 retval = iso_mode(bkpinfo, mountlist, raidlist, FALSE); 3551 } else if (argc == 2 && strcmp(argv[1], "--mbr") == 0) { 3552 iamhere("mbr"); 3553 retval = mount_all_devices(mountlist, TRUE); 3554 if (!retval) { 3555 retval += run_boot_loader(FALSE); 3556 retval += unmount_all_devices(mountlist); 3557 } 3558 if (retval) { 3559 log_to_screen("Failed to write Master Boot Record"); 3560 } 3561 } else if (argc == 2 && strcmp(argv[1], "--isonuke") == 0) { 3562 iamhere("isonuke"); 3563 retval = iso_mode(bkpinfo, mountlist, raidlist, TRUE); 3564 } else if (argc != 1) { 3565 log_to_screen("Invalid paremeters"); 3566 paranoid_MR_finish(1); 3567 } else { 3568 iamhere("catchall (no mode specified in command-line call"); 3569 retval += catchall_mode(bkpinfo, mountlist, raidlist); 3570 } 3571 } 3572 3573 /* clean up at the end */ 3574 if (retval) { 3575 if (does_file_exist("/tmp/changed.files")) { 3576 log_to_screen 3577 ("See /tmp/changed.files for list of files that have changed."); 3578 } 3579 mvaddstr_and_log_it(g_currentY++, 3580 0, 3581 "Run complete. Errors were reported. Please review the logfile."); 3582 } else { 3583 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 3584 mvaddstr_and_log_it(g_currentY++, 3585 0, 3586 "Run complete. Please remove floppy/CD/media and reboot."); 3587 } else { 3588 run_program_and_log_output("sync", FALSE); 3589 if (is_this_device_mounted(MNT_CDROM)) { 3590 res = 3591 run_program_and_log_output("umount " MNT_CDROM, FALSE); 3592 } else { 3593 res = 0; 3594 } 3595 3596 if (!bkpinfo->please_dont_eject) { 3597 res = eject_device("/dev/cdrom"); 3592 3598 /* 3593 3599 if (res) … … 3596 3602 } 3597 3603 */ 3598 3599 mvaddstr_and_log_it(g_currentY++,3600 3601 "Run complete. Please remove media and reboot.");3602 }3603 3604 } 3605 mvaddstr_and_log_it(g_currentY++, 3606 0, 3607 "Run complete. Please remove media and reboot."); 3608 } 3609 } 3604 3610 3605 3611 // g_I_have_just_nuked is set true by nuke_mode() just before it returns 3606 if ( g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) 3607 { 3608 if (!system("which post-nuke > /dev/null 2> /dev/null")) 3609 { 3610 log_msg(1, "post-nuke found; running..."); 3611 if (mount_all_devices(mountlist, TRUE)) 3612 { 3613 log_to_screen("Unable to re-mount partitions for post-nuke stuff"); 3614 } 3615 else 3616 { 3617 log_msg(1, "Re-mounted partitions for post-nuke stuff"); 3618 sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, retval); 3619 if (!g_text_mode) { newtSuspend(); } 3620 log_msg(2, "Calling '%s'", tmp); 3621 if ((res=system(tmp))) { log_OS_error(tmp); } 3622 if (!g_text_mode) { newtResume(); } 3612 if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) { 3613 if (!system("which post-nuke > /dev/null 2> /dev/null")) { 3614 log_msg(1, "post-nuke found; running..."); 3615 if (mount_all_devices(mountlist, TRUE)) { 3616 log_to_screen 3617 ("Unable to re-mount partitions for post-nuke stuff"); 3618 } else { 3619 log_msg(1, "Re-mounted partitions for post-nuke stuff"); 3620 sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, 3621 retval); 3622 if (!g_text_mode) { 3623 newtSuspend(); 3624 } 3625 log_msg(2, "Calling '%s'", tmp); 3626 if ((res = system(tmp))) { 3627 log_OS_error(tmp); 3628 } 3629 if (!g_text_mode) { 3630 newtResume(); 3631 } 3623 3632 // newtCls(); 3624 3625 3626 3627 3628 3629 3633 log_msg(1, "post-nuke returned w/ res=%d", res); 3634 } 3635 unmount_all_devices(mountlist); 3636 log_msg(1, "I've finished post-nuking."); 3637 } 3638 } 3630 3639 /* 3631 3640 log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now."); … … 3633 3642 wait_until_software_raids_are_prepped("/proc/mdstat", 100); 3634 3643 log_to_screen("Thank you."); 3635 */ 3636 unlink( "/tmp/mondo-run-prog.tmp" ); 3637 set_signals( FALSE ); 3638 sprintf( tmp, "rm -Rf %s", bkpinfo->tmpdir ); 3639 run_program_and_log_output ( tmp, FALSE ); 3640 log_to_screen( "Restore log copied to /tmp/mondo-restore.log on your hard disk" ); 3641 sprintf( tmp, "Mondo-restore is exiting (retval=%d) ",retval); 3642 log_to_screen( tmp ); 3643 sprintf(tmp, "umount %s", bkpinfo->isodir); 3644 run_program_and_log_output(tmp, 5); 3645 paranoid_free(mountlist); 3646 paranoid_free(raidlist); 3647 if (am_I_in_disaster_recovery_mode()) 3648 { run_program_and_log_output("mount / -o remount,rw",2); } // for b0rken distros 3649 paranoid_MR_finish( retval ); // frees global stuff plus bkpinfo 3650 free_libmondo_global_strings(); // it's fine to have this here :) really :) 3651 paranoid_free(a); 3652 paranoid_free(b); 3653 paranoid_free(tmp); 3654 3655 unlink("/tmp/filelist.full"); 3656 unlink("/tmp/filelist.full.gz"); 3657 3658 exit( retval ); 3644 */ 3645 unlink("/tmp/mondo-run-prog.tmp"); 3646 set_signals(FALSE); 3647 sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir); 3648 run_program_and_log_output(tmp, FALSE); 3649 log_to_screen 3650 ("Restore log copied to /tmp/mondo-restore.log on your hard disk"); 3651 sprintf(tmp, 3652 "Mondo-restore is exiting (retval=%d) ", 3653 retval); 3654 log_to_screen(tmp); 3655 sprintf(tmp, "umount %s", bkpinfo->isodir); 3656 run_program_and_log_output(tmp, 5); 3657 paranoid_free(mountlist); 3658 paranoid_free(raidlist); 3659 if (am_I_in_disaster_recovery_mode()) { 3660 run_program_and_log_output("mount / -o remount,rw", 2); 3661 } // for b0rken distros 3662 paranoid_MR_finish(retval); // frees global stuff plus bkpinfo 3663 free_libmondo_global_strings(); // it's fine to have this here :) really :) 3664 paranoid_free(a); 3665 paranoid_free(b); 3666 paranoid_free(tmp); 3667 3668 unlink("/tmp/filelist.full"); 3669 unlink("/tmp/filelist.full.gz"); 3670 3671 exit(retval); 3659 3672 } 3660 3673 … … 3670 3683 *END_MONDO-RESTORE.C * 3671 3684 **************************************************************************/ 3672 -
trunk/mondo/mondo/mondorestore/mondo-restore.h
r30 r59 1 1 /* mondo-restore.h 2 * $Id : mondo-restore.h,v 1.3 2004/06/21 20:20:37 hugo Exp$2 * $Id$ 3 3 */ 4 4 … … 7 7 **************************************************************************/ 8 8 9 void ask_about_these_imagedevs(char*,char*); 10 int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself*); 11 void find_pathname_of_executable_preferably_in_RESTORING(char *, char*, char*); 12 int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 13 int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 14 int compare_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 15 int iso_mode(struct s_bkpinfo *bkpinfo, 16 struct mountlist_itself *mountlist, 17 struct raidlist_itself *raidlist, 18 bool nuke_me_please); 19 int restore_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 20 int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, struct s_node*, char*); 21 int restore_a_biggiefile_from_stream(struct s_bkpinfo*, char*, long , char*, long long, struct s_node*, int, char*); 22 int restore_a_tarball_from_CD(char *, long, struct s_node*); 23 int restore_a_tarball_from_stream(struct s_bkpinfo*, char *, long, struct s_node*, long long, char*, char*); 24 int restore_all_biggiefiles_from_CD(struct s_bkpinfo*, struct s_node*); 25 int restore_all_biggiefiles_from_stream(struct s_bkpinfo*, struct s_node*); 26 int restore_all_tarballs_from_CD(struct s_bkpinfo*, struct s_node*); 27 int restore_all_tarballs_from_stream(struct s_bkpinfo*, struct s_node*); 28 int restore_everything(struct s_bkpinfo*,struct s_node*); 29 int restore_live_from_monitas_server(struct s_bkpinfo *, char*, char*, char*); 30 int restore_to_live_filesystem(struct s_bkpinfo*); 31 void swap_mountlist_entries(struct mountlist_itself*,int,int); 32 void sort_mountlist_by_mountpoint(struct mountlist_itself*,bool); 33 void sort_mountlist_by_device(struct mountlist_itself*); 34 int what_number_cd_is_this(struct s_bkpinfo*); 9 void ask_about_these_imagedevs(char *, char *); 10 int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *, 11 struct raidlist_itself *); 12 void find_pathname_of_executable_preferably_in_RESTORING(char *, char *, 13 char *); 14 int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *, 15 struct raidlist_itself *); 16 int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *, 17 struct raidlist_itself *); 18 int compare_mode(struct s_bkpinfo *, struct mountlist_itself *, 19 struct raidlist_itself *); 20 int iso_mode(struct s_bkpinfo *bkpinfo, struct mountlist_itself *mountlist, 21 struct raidlist_itself *raidlist, bool nuke_me_please); 22 int restore_mode(struct s_bkpinfo *, struct mountlist_itself *, 23 struct raidlist_itself *); 24 int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, struct s_node *, 25 char *); 26 int restore_a_biggiefile_from_stream(struct s_bkpinfo *, char *, long, 27 char *, long long, struct s_node *, 28 int, char *); 29 int restore_a_tarball_from_CD(char *, long, struct s_node *); 30 int restore_a_tarball_from_stream(struct s_bkpinfo *, char *, long, 31 struct s_node *, long long, char *, 32 char *); 33 int restore_all_biggiefiles_from_CD(struct s_bkpinfo *, struct s_node *); 34 int restore_all_biggiefiles_from_stream(struct s_bkpinfo *, 35 struct s_node *); 36 int restore_all_tarballs_from_CD(struct s_bkpinfo *, struct s_node *); 37 int restore_all_tarballs_from_stream(struct s_bkpinfo *, struct s_node *); 38 int restore_everything(struct s_bkpinfo *, struct s_node *); 39 int restore_live_from_monitas_server(struct s_bkpinfo *, char *, char *, 40 char *); 41 int restore_to_live_filesystem(struct s_bkpinfo *); 42 void swap_mountlist_entries(struct mountlist_itself *, int, int); 43 void sort_mountlist_by_mountpoint(struct mountlist_itself *, bool); 44 void sort_mountlist_by_device(struct mountlist_itself *); 45 int what_number_cd_is_this(struct s_bkpinfo *); -
trunk/mondo/mondo/mondorestore/mondo-rstr-compare-EXT.h
r30 r59 2 2 3 3 4 extern int compare_to_CD(struct s_bkpinfo *);5 extern int compare_to_cdstream(struct s_bkpinfo *);6 extern int compare_to_tape(struct s_bkpinfo *);7 extern int compare_mode( struct s_bkpinfo *bkpinfo,8 struct mountlist_itself *mountlist,9 4 extern int compare_to_CD(struct s_bkpinfo *); 5 extern int compare_to_cdstream(struct s_bkpinfo *); 6 extern int compare_to_tape(struct s_bkpinfo *); 7 extern int compare_mode(struct s_bkpinfo *bkpinfo, 8 struct mountlist_itself *mountlist, 9 struct raidlist_itself *raidlist); -
trunk/mondo/mondo/mondorestore/mondo-rstr-compare.c
r30 r59 5 5 copyright : (C) 2000 by Hugo Rabson 6 6 email : Hugo Rabson <hugorabson@msn.com> 7 cvsid : $Id : mondo-rstr-compare.c,v 1.1 2004/06/10 15:29:13 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 65 65 #include "mondo-rstr-tools-EXT.h" 66 66 67 //static char cvsid[] = "$Id : mondo-rstr-compare.c,v 1.1 2004/06/10 15:29:13 hugo Exp$";68 69 void popup_changelist_from_file(char *);67 //static char cvsid[] = "$Id$"; 68 69 void popup_changelist_from_file(char *); 70 70 71 71 … … 80 80 * @note This function uses an MD5 checksum. 81 81 */ 82 int 83 compare_a_biggiefile(struct s_bkpinfo *bkpinfo, long bigfileno) 82 int compare_a_biggiefile(struct s_bkpinfo *bkpinfo, long bigfileno) 84 83 { 85 84 86 87 85 FILE *fin; 86 FILE *fout; 88 87 89 88 /** needs malloc *******/ 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 89 char *checksum_ptr; 90 char *original_cksum_ptr; 91 char *bigfile_fname_ptr; 92 char *tmp_ptr; 93 char *command_ptr; 94 95 char *checksum, *original_cksum, *bigfile_fname, *tmp, *command; 96 97 char *p; 98 int i; 99 int retval = 0; 100 101 struct s_filename_and_lstat_info biggiestruct; 102 103 malloc_string(checksum); 104 malloc_string(original_cksum); 105 malloc_string(bigfile_fname); 106 malloc_string(tmp); 107 malloc_string(command); 108 malloc_string(checksum_ptr); 109 malloc_string(original_cksum_ptr); 110 malloc_string(bigfile_fname_ptr); 111 malloc_string(command_ptr); 112 malloc_string(tmp_ptr); 113 115 114 /********************************************************************* 116 115 * allocate memory clear test sab 16 feb 2003 * 117 116 *********************************************************************/ 118 assert(bkpinfo!=NULL);119 memset(checksum_ptr, '\0', sizeof(checksum));120 memset (original_cksum_ptr, '\0', sizeof(original_cksum));121 memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));122 memset(tmp_ptr, '\0', sizeof(tmp));123 memset ( command_ptr, '\0', sizeof( command ));117 assert(bkpinfo != NULL); 118 memset(checksum_ptr, '\0', sizeof(checksum)); 119 memset(original_cksum_ptr, '\0', sizeof(original_cksum)); 120 memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname)); 121 memset(tmp_ptr, '\0', sizeof(tmp)); 122 memset(command_ptr, '\0', sizeof(command)); 124 123 /** end **/ 125 124 126 if ( !does_file_exist( slice_fname(bigfileno, 0, ARCHIVES_PATH, "" ) ) ) 127 { 128 if ( does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST" ) ) 129 { 130 insist_on_this_cd_number(bkpinfo, ( ++g_current_media_number ) ); 131 } 132 else 133 { 134 sprintf(tmp_ptr, "No CD's left. No biggiefiles left. No prob, Bob." ); 135 log_msg(2, tmp_ptr ); 136 return( 0 ); 137 } 138 } 139 if ( !( fin = fopen(slice_fname( bigfileno, 0, ARCHIVES_PATH, "" ), "r" ) ) ) 140 { 141 sprintf( tmp_ptr, 142 "Cannot open bigfile %ld (%s)'s info file", 143 bigfileno + 1, bigfile_fname_ptr); 144 log_to_screen( tmp_ptr ); 145 return( 1 ); 146 } 147 fread( ( void* )&biggiestruct, 1, sizeof( biggiestruct ), fin); 148 paranoid_fclose( fin ); 149 150 strcpy( checksum_ptr, biggiestruct.checksum ); 151 strcpy( bigfile_fname_ptr, biggiestruct.filename ); 152 153 log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename ); 154 log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum ); 155 156 sprintf( tmp_ptr, "Comparing %s", bigfile_fname_ptr); 157 158 if (!g_text_mode) 159 { 160 newtDrawRootText( 0, 22, tmp_ptr); 161 newtRefresh(); 162 } 163 if ( !checksum[0] ) { 164 log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr ); 165 } 166 if ( !strncmp( bigfile_fname_ptr, "/dev/", 5 ) ) 167 { 168 strcpy( original_cksum_ptr, "IGNORE" ); 169 } 170 else 171 { 172 sprintf( command_ptr, 173 "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors.txt", 174 MNT_RESTORING, bigfile_fname_ptr); 175 } 176 log_msg(2, command_ptr ); 177 paranoid_system( "cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null" ); 178 if ( system( command_ptr ) ) 179 { 180 log_OS_error( "Warning - command failed" ); 181 original_cksum[0] = '\0'; 182 return( 1 ); 183 } 184 else 185 { 186 if ( !(fin = fopen( "/tmp/md5sum.txt", "r" ) ) ) 187 { 188 log_msg(2, "Unable to open /tmp/md5sum.txt; can't get live checksum" ); 189 original_cksum[0] = '\0'; 190 return( 1 ); 191 } 192 else 193 { 194 fgets( original_cksum_ptr, MAX_STR_LEN - 1, fin ); 195 paranoid_fclose( fin ); 196 for(i = strlen( original_cksum_ptr ); i > 0 && original_cksum[i-1] < 32; i-- ); 197 original_cksum[i] = '\0'; 198 p = ( char* ) strchr( original_cksum_ptr, ' ' ); 199 if ( p ) 200 { 201 *p = '\0'; 202 } 203 } 204 } 205 sprintf( tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname_ptr); 206 if ( !strcmp(checksum_ptr, original_cksum_ptr ) != 0 ) 207 { 208 strcat( tmp_ptr," ... OK"); 209 } 210 else 211 { 212 strcat( tmp_ptr, "... changed" ); 213 retval++; 214 } 215 log_msg(1, tmp_ptr ); 216 if ( retval ) 217 { 218 if ( !( fout = fopen("/tmp/changed.txt", "a") ) ) 219 { 220 fatal_error( "Cannot openout changed.txt"); 221 } 222 fprintf( fout, "%s\n", bigfile_fname_ptr ); 223 paranoid_fclose( fout ); 224 } 225 226 paranoid_free (original_cksum_ptr); 227 paranoid_free (original_cksum); 228 paranoid_free (bigfile_fname_ptr); 229 paranoid_free (bigfile_fname); 230 paranoid_free (checksum_ptr); 231 paranoid_free (checksum); 232 paranoid_free (command_ptr); 233 paranoid_free (command); 234 paranoid_free (tmp_ptr); 235 paranoid_free (tmp); 236 237 return( retval ); 125 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) { 126 if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) { 127 insist_on_this_cd_number(bkpinfo, (++g_current_media_number)); 128 } else { 129 sprintf(tmp_ptr, 130 "No CD's left. No biggiefiles left. No prob, Bob."); 131 log_msg(2, tmp_ptr); 132 return (0); 133 } 134 } 135 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) { 136 sprintf(tmp_ptr, 137 "Cannot open bigfile %ld (%s)'s info file", 138 bigfileno + 1, bigfile_fname_ptr); 139 log_to_screen(tmp_ptr); 140 return (1); 141 } 142 fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin); 143 paranoid_fclose(fin); 144 145 strcpy(checksum_ptr, biggiestruct.checksum); 146 strcpy(bigfile_fname_ptr, biggiestruct.filename); 147 148 log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename); 149 log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum); 150 151 sprintf(tmp_ptr, "Comparing %s", bigfile_fname_ptr); 152 153 if (!g_text_mode) { 154 newtDrawRootText(0, 22, tmp_ptr); 155 newtRefresh(); 156 } 157 if (!checksum[0]) { 158 log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr); 159 } 160 if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) { 161 strcpy(original_cksum_ptr, "IGNORE"); 162 } else { 163 sprintf(command_ptr, 164 "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors.txt", 165 MNT_RESTORING, bigfile_fname_ptr); 166 } 167 log_msg(2, command_ptr); 168 paranoid_system 169 ("cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null"); 170 if (system(command_ptr)) { 171 log_OS_error("Warning - command failed"); 172 original_cksum[0] = '\0'; 173 return (1); 174 } else { 175 if (!(fin = fopen("/tmp/md5sum.txt", "r"))) { 176 log_msg(2, 177 "Unable to open /tmp/md5sum.txt; can't get live checksum"); 178 original_cksum[0] = '\0'; 179 return (1); 180 } else { 181 fgets(original_cksum_ptr, MAX_STR_LEN - 1, fin); 182 paranoid_fclose(fin); 183 for (i = strlen(original_cksum_ptr); 184 i > 0 && original_cksum[i - 1] < 32; i--); 185 original_cksum[i] = '\0'; 186 p = (char *) strchr(original_cksum_ptr, ' '); 187 if (p) { 188 *p = '\0'; 189 } 190 } 191 } 192 sprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1, 193 bigfile_fname_ptr); 194 if (!strcmp(checksum_ptr, original_cksum_ptr) != 0) { 195 strcat(tmp_ptr, " ... OK"); 196 } else { 197 strcat(tmp_ptr, "... changed"); 198 retval++; 199 } 200 log_msg(1, tmp_ptr); 201 if (retval) { 202 if (!(fout = fopen("/tmp/changed.txt", "a"))) { 203 fatal_error("Cannot openout changed.txt"); 204 } 205 fprintf(fout, "%s\n", bigfile_fname_ptr); 206 paranoid_fclose(fout); 207 } 208 209 paranoid_free(original_cksum_ptr); 210 paranoid_free(original_cksum); 211 paranoid_free(bigfile_fname_ptr); 212 paranoid_free(bigfile_fname); 213 paranoid_free(checksum_ptr); 214 paranoid_free(checksum); 215 paranoid_free(command_ptr); 216 paranoid_free(command); 217 paranoid_free(tmp_ptr); 218 paranoid_free(tmp); 219 220 return (retval); 238 221 } 239 222 … … 248 231 * @return 0 for success, nonzero for failure. 249 232 */ 250 int 251 compare_all_biggiefiles(struct s_bkpinfo*bkpinfo) 233 int compare_all_biggiefiles(struct s_bkpinfo *bkpinfo) 252 234 { 253 int retval = 0; 254 int res; 255 long noof_biggiefiles,bigfileno = 0; 256 char tmp[MAX_STR_LEN]; 257 258 assert(bkpinfo!=NULL); 259 log_msg(1, "Comparing biggiefiles" ); 260 261 if ( length_of_file(BIGGIELIST) < 6 ) 262 { 263 log_msg(1, "OK, really teeny-tiny biggielist; not comparing biggiefiles" ); 264 return( 0 ); 265 } 266 noof_biggiefiles = count_lines_in_file(BIGGIELIST); 267 if (noof_biggiefiles <= 0 ) 268 { 269 log_msg(1, "OK, no biggiefiles; not comparing biggiefiles"); 270 return( 0 ); 271 } 272 mvaddstr_and_log_it( g_currentY, 0, "Comparing large files "); 273 open_progress_form("Comparing large files", "I am now comparing the large files" , "against the filesystem. Please wait.", 274 "", 275 noof_biggiefiles ); 276 for( bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++ ) 277 { 278 sprintf( tmp, "Comparing big file #%ld", bigfileno + 1 ); 279 log_msg(1, tmp ); 280 update_progress_form( tmp ); 281 res = compare_a_biggiefile( bkpinfo, bigfileno ); 282 retval += res; 283 g_current_progress++; 284 } 285 close_progress_form(); 286 return( 0 ); 287 if ( retval ) 288 { 289 mvaddstr_and_log_it( g_currentY++, 74, "Errors." ); 290 } 291 else 292 { 293 mvaddstr_and_log_it( g_currentY++,74, "Done." ); 294 } 295 return( retval ); 235 int retval = 0; 236 int res; 237 long noof_biggiefiles, bigfileno = 0; 238 char tmp[MAX_STR_LEN]; 239 240 assert(bkpinfo != NULL); 241 log_msg(1, "Comparing biggiefiles"); 242 243 if (length_of_file(BIGGIELIST) < 6) { 244 log_msg(1, 245 "OK, really teeny-tiny biggielist; not comparing biggiefiles"); 246 return (0); 247 } 248 noof_biggiefiles = count_lines_in_file(BIGGIELIST); 249 if (noof_biggiefiles <= 0) { 250 log_msg(1, "OK, no biggiefiles; not comparing biggiefiles"); 251 return (0); 252 } 253 mvaddstr_and_log_it(g_currentY, 0, 254 "Comparing large files "); 255 open_progress_form("Comparing large files", 256 "I am now comparing the large files", 257 "against the filesystem. Please wait.", "", 258 noof_biggiefiles); 259 for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) { 260 sprintf(tmp, "Comparing big file #%ld", bigfileno + 1); 261 log_msg(1, tmp); 262 update_progress_form(tmp); 263 res = compare_a_biggiefile(bkpinfo, bigfileno); 264 retval += res; 265 g_current_progress++; 266 } 267 close_progress_form(); 268 return (0); 269 if (retval) { 270 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 271 } else { 272 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 273 } 274 return (retval); 296 275 } 276 297 277 /************************************************************************** 298 278 *END_COMPARE_ALL_BIGGIEFILES * … … 308 288 * @return 0 for success, nonzero for failure. 309 289 */ 310 int 311 compare_a_tarball( char *tarball_fname, int current_tarball_number ) 290 int compare_a_tarball(char *tarball_fname, int current_tarball_number) 312 291 { 313 314 315 316 317 318 292 int retval = 0; 293 int res; 294 long noof_lines; 295 long archiver_errors; 296 bool use_star; 297 319 298 /*** needs malloc *********/ 320 char *command, *tmp, *filelist_name, *logfile, *archiver_exe, *compressor_exe; 321 322 malloc_string(command); 323 malloc_string(tmp);324 malloc_string(filelist_name);325 malloc_string(logfile);326 malloc_string(archiver_exe);327 malloc_string(compressor_exe);328 329 use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE; 330 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);331 sprintf( logfile, "/tmp/afio.log.%d", current_tarball_number);332 sprintf( filelist_name, MNT_CDROM"/archives/filelist.%d", current_tarball_number);333 334 noof_lines = count_lines_in_file( filelist_name);335 336 if ( strstr( tarball_fname, ".bz2") ) 337 { 338 strcpy( compressor_exe, "bzip2"); 339 } 340 else if ( strstr (tarball_fname, ".lzo") ) 341 { 342 strcpy( compressor_exe, "lzop" ); 343 } 344 else 345 { 346 compressor_exe[0] = '\0'; 347 } 348 349 if (use_star) 350 { strcpy(archiver_exe, "star");}351 else 352 { strcpy(archiver_exe, "afio"); } 353 354 if (compressor_exe[0]) 355 { 356 strcpy(tmp, compressor_exe); 357 if (!find_home_of_exe(tmp)) 358 { fatal_error("(compare_a_tarball) Compression program missing"); } 359 if (use_star) // star 360 { 361 if (!strcmp(compressor_exe, "bzip2"))362 { strcat(archiver_exe, " -bz"); }363 else { fatal_error("(compare_a_tarball) Please use only bzip2 with star"); }364 }365 else// afio366 367 368 }369 299 char *command, *tmp, *filelist_name, *logfile, *archiver_exe, 300 *compressor_exe; 301 302 malloc_string(command); 303 malloc_string(tmp); 304 malloc_string(filelist_name); 305 malloc_string(logfile); 306 malloc_string(archiver_exe); 307 malloc_string(compressor_exe); 308 309 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 310 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 311 sprintf(logfile, "/tmp/afio.log.%d", current_tarball_number); 312 sprintf(filelist_name, MNT_CDROM "/archives/filelist.%d", 313 current_tarball_number); 314 315 noof_lines = count_lines_in_file(filelist_name); 316 317 if (strstr(tarball_fname, ".bz2")) { 318 strcpy(compressor_exe, "bzip2"); 319 } else if (strstr(tarball_fname, ".lzo")) { 320 strcpy(compressor_exe, "lzop"); 321 } else { 322 compressor_exe[0] = '\0'; 323 } 324 325 if (use_star) { 326 strcpy(archiver_exe, "star"); 327 } else { 328 strcpy(archiver_exe, "afio"); 329 } 330 331 if (compressor_exe[0]) { 332 strcpy(tmp, compressor_exe); 333 if (!find_home_of_exe(tmp)) { 334 fatal_error("(compare_a_tarball) Compression program missing"); 335 } 336 if (use_star) // star 337 { 338 if (!strcmp(compressor_exe, "bzip2")) { 339 strcat(archiver_exe, " -bz"); 340 } else { 341 fatal_error 342 ("(compare_a_tarball) Please use only bzip2 with star"); 343 } 344 } else // afio 345 { 346 sprintf(compressor_exe, "-P %s -Z", tmp); 347 } 348 } 370 349 // star -diff H=star -bz file=.... 371 350 … … 375 354 #define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE 376 355 #endif 377 if (use_star) // doesn't use compressor_exe 378 { 379 sprintf( command, 380 "%s -diff H=star file=%s >> %s 2>> %s", 381 archiver_exe, tarball_fname, logfile, logfile); 382 } 383 else 384 { 385 sprintf( command, 386 "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", 387 archiver_exe, 388 TAPE_BLOCK_SIZE, 389 BUFSIZE, 390 compressor_exe, tarball_fname, 391 logfile, 392 logfile); 393 } 356 if (use_star) // doesn't use compressor_exe 357 { 358 sprintf(command, 359 "%s -diff H=star file=%s >> %s 2>> %s", 360 archiver_exe, tarball_fname, logfile, logfile); 361 } else { 362 sprintf(command, 363 "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", 364 archiver_exe, 365 TAPE_BLOCK_SIZE, 366 BUFSIZE, compressor_exe, tarball_fname, logfile, logfile); 367 } 394 368 #undef BUFSIZE 395 369 396 res = system( command ); 397 retval += res; 398 if ( res ) 399 { 400 log_OS_error( command ); 401 sprintf( tmp, "Warning - afio returned error = %d", res ); 402 } 403 if (length_of_file(logfile)>5) 404 { 405 sprintf(command, 406 "cat %s | sed s/': \\\"'/\\|/ | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort | uniq | grep -vx \"dev/.*\" >> /tmp/changed.txt", 407 logfile); 408 system(command); 409 archiver_errors = count_lines_in_file( logfile ); 410 } 411 else 412 { 413 archiver_errors = 0; 414 } 415 sprintf(tmp, "%ld difference%c in fileset #%d ", 416 archiver_errors, (archiver_errors != 1) ? 's' : ' ', current_tarball_number); 417 if (archiver_errors) 418 { 419 sprintf(tmp, 420 "Differences found while processing fileset #%d ", 421 current_tarball_number); 422 log_msg(1, tmp ); 423 } 424 unlink( logfile ); 425 paranoid_free(command); 426 paranoid_free(tmp); 427 paranoid_free(filelist_name); 428 paranoid_free(logfile); 429 malloc_string(archiver_exe); 430 malloc_string(compressor_exe); 431 return( retval ); 370 res = system(command); 371 retval += res; 372 if (res) { 373 log_OS_error(command); 374 sprintf(tmp, "Warning - afio returned error = %d", res); 375 } 376 if (length_of_file(logfile) > 5) { 377 sprintf(command, 378 "cat %s | sed s/': \\\"'/\\|/ | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort | uniq | grep -vx \"dev/.*\" >> /tmp/changed.txt", 379 logfile); 380 system(command); 381 archiver_errors = count_lines_in_file(logfile); 382 } else { 383 archiver_errors = 0; 384 } 385 sprintf(tmp, "%ld difference%c in fileset #%d ", 386 archiver_errors, (archiver_errors != 1) ? 's' : ' ', 387 current_tarball_number); 388 if (archiver_errors) { 389 sprintf(tmp, 390 "Differences found while processing fileset #%d ", 391 current_tarball_number); 392 log_msg(1, tmp); 393 } 394 unlink(logfile); 395 paranoid_free(command); 396 paranoid_free(tmp); 397 paranoid_free(filelist_name); 398 paranoid_free(logfile); 399 malloc_string(archiver_exe); 400 malloc_string(compressor_exe); 401 return (retval); 432 402 } 403 433 404 /************************************************************************** 434 405 *END_COMPARE_A_TARBALL * … … 441 412 * @return 0 for success, nonzero for failure. 442 413 */ 443 int 444 compare_all_tarballs( struct s_bkpinfo *bkpinfo ) 414 int compare_all_tarballs(struct s_bkpinfo *bkpinfo) 445 415 { 446 447 448 416 int retval = 0; 417 int res; 418 int current_tarball_number = 0; 449 419 450 420 /** needs malloc **********/ 451 452 char *tarball_fname, *progress_str, *tmp; 453 long max_val; 454 455 malloc_string(tarball_fname); 456 malloc_string(progress_str); 457 malloc_string(tmp); 458 459 assert(bkpinfo!=NULL); 460 mvaddstr_and_log_it( g_currentY,0, "Comparing archives" ); 461 read_cfg_var( g_mondo_cfg_file, "last-filelist-number", tmp ); 462 463 max_val = atol( tmp ); 464 sprintf( progress_str, "Comparing with %s #%d ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number ); 465 466 open_progress_form("Comparing files", 467 "Comparing tarballs against filesystem.", 468 "Please wait. This may take some time.", 469 progress_str, 470 max_val); 471 472 log_to_screen( progress_str ); 473 474 for( ;; ) 475 { 476 insist_on_this_cd_number( bkpinfo, g_current_media_number ); 477 update_progress_form( progress_str ); 478 sprintf( tarball_fname, 479 MNT_CDROM"/archives/%d.afio.bz2", 480 current_tarball_number); 481 482 if ( !does_file_exist( tarball_fname ) ) 483 { 484 sprintf( tarball_fname, MNT_CDROM"/archives/%d.afio.lzo", current_tarball_number ); 485 } 486 if (!does_file_exist ( tarball_fname ) ) 487 { 488 sprintf(tarball_fname, MNT_CDROM"/archives/%d.afio.", 489 current_tarball_number); 490 } 491 if (!does_file_exist ( tarball_fname ) ) 492 { 493 sprintf(tarball_fname, MNT_CDROM"/archives/%d.star.bz2", 494 current_tarball_number); 495 } 496 if (!does_file_exist ( tarball_fname ) ) 497 { 498 sprintf(tarball_fname, MNT_CDROM"/archives/%d.star.", 499 current_tarball_number); 500 } 501 if ( !does_file_exist( tarball_fname ) ) 502 { 503 if ( !does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST" ) || 504 system( "find "MNT_CDROM"/archives/slice* > /dev/null 2> /dev/null" ) 505 == 0 ) 506 { 507 log_msg(2, "OK, I think I'm done with tarballs..." ); 508 break; 509 } 510 log_msg(2, "OK, I think it's time for another CD..." ); 511 g_current_media_number++; 512 sprintf( progress_str, "Comparing with %s #%d ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number ); 513 log_to_screen( progress_str ); 514 } 515 else 516 { 517 res = 518 compare_a_tarball( tarball_fname, current_tarball_number ); 519 520 g_current_progress++; 521 current_tarball_number++; 522 } 523 } 524 close_progress_form(); 525 if ( retval ) 526 { 527 mvaddstr_and_log_it( g_currentY++,74, "Errors." ); 528 } 529 else 530 { 531 mvaddstr_and_log_it( g_currentY++, 532 74, 533 "Done."); 534 } 535 paranoid_free(tarball_fname); 536 paranoid_free(progress_str); 537 paranoid_free(tmp); 538 return(retval); 421 422 char *tarball_fname, *progress_str, *tmp; 423 long max_val; 424 425 malloc_string(tarball_fname); 426 malloc_string(progress_str); 427 malloc_string(tmp); 428 429 assert(bkpinfo != NULL); 430 mvaddstr_and_log_it(g_currentY, 0, "Comparing archives"); 431 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 432 433 max_val = atol(tmp); 434 sprintf(progress_str, "Comparing with %s #%d ", 435 media_descriptor_string(bkpinfo->backup_media_type), 436 g_current_media_number); 437 438 open_progress_form("Comparing files", 439 "Comparing tarballs against filesystem.", 440 "Please wait. This may take some time.", 441 progress_str, max_val); 442 443 log_to_screen(progress_str); 444 445 for (;;) { 446 insist_on_this_cd_number(bkpinfo, g_current_media_number); 447 update_progress_form(progress_str); 448 sprintf(tarball_fname, 449 MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number); 450 451 if (!does_file_exist(tarball_fname)) { 452 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo", 453 current_tarball_number); 454 } 455 if (!does_file_exist(tarball_fname)) { 456 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.", 457 current_tarball_number); 458 } 459 if (!does_file_exist(tarball_fname)) { 460 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2", 461 current_tarball_number); 462 } 463 if (!does_file_exist(tarball_fname)) { 464 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.", 465 current_tarball_number); 466 } 467 if (!does_file_exist(tarball_fname)) { 468 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST") || 469 system("find " MNT_CDROM 470 "/archives/slice* > /dev/null 2> /dev/null") 471 == 0) { 472 log_msg(2, "OK, I think I'm done with tarballs..."); 473 break; 474 } 475 log_msg(2, "OK, I think it's time for another CD..."); 476 g_current_media_number++; 477 sprintf(progress_str, "Comparing with %s #%d ", 478 media_descriptor_string(bkpinfo->backup_media_type), 479 g_current_media_number); 480 log_to_screen(progress_str); 481 } else { 482 res = compare_a_tarball(tarball_fname, current_tarball_number); 483 484 g_current_progress++; 485 current_tarball_number++; 486 } 487 } 488 close_progress_form(); 489 if (retval) { 490 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 491 } else { 492 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 493 } 494 paranoid_free(tarball_fname); 495 paranoid_free(progress_str); 496 paranoid_free(tmp); 497 return (retval); 539 498 } 499 540 500 /************************************************************************** 541 501 *END_COMPARE_ALL_TARBALLS * … … 554 514 * @return 0 for success, nonzero for failure. 555 515 */ 556 int 557 compare_to_CD( struct s_bkpinfo *bkpinfo ) 516 int compare_to_CD(struct s_bkpinfo *bkpinfo) 558 517 { 559 518 /** needs malloc *********/ 560 char *tmp, *cwd, *new, *command; 561 int resA = 0; 562 int resB = 0; 563 long noof_changed_files; 564 565 malloc_string(tmp); 566 malloc_string(cwd); 567 malloc_string(new); 568 malloc_string(command); 569 570 assert(bkpinfo!=NULL); 571 572 getcwd( cwd, MAX_STR_LEN - 1 ); 573 chdir( bkpinfo->restore_path ); 574 getcwd( new, MAX_STR_LEN - 1 ); 575 sprintf( tmp, "new path is %s", new ); 576 insist_on_this_cd_number( bkpinfo, g_current_media_number ); 577 unlink( "/tmp/changed.txt" ); 578 579 resA = compare_all_tarballs( bkpinfo ); 580 resB = compare_all_biggiefiles( bkpinfo ); 581 chdir( cwd ); 582 noof_changed_files = count_lines_in_file( "/tmp/changed.txt" ); 583 if ( noof_changed_files ) 584 { 585 sprintf( tmp, "%ld files do not match the backup ", 586 noof_changed_files ); 587 // mvaddstr_and_log_it( g_currentY++, 0, tmp ); 588 log_to_screen (tmp); 589 sprintf(command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE ); 590 paranoid_system( command ); 591 } 592 else 593 { 594 sprintf( tmp, "All files match the backup "); 595 mvaddstr_and_log_it( g_currentY++, 0, tmp ); 596 log_to_screen( tmp ); 597 } 598 599 paranoid_free(tmp); 600 paranoid_free(cwd); 601 paranoid_free(new); 602 paranoid_free(command); 603 604 return( resA + resB ); 519 char *tmp, *cwd, *new, *command; 520 int resA = 0; 521 int resB = 0; 522 long noof_changed_files; 523 524 malloc_string(tmp); 525 malloc_string(cwd); 526 malloc_string(new); 527 malloc_string(command); 528 529 assert(bkpinfo != NULL); 530 531 getcwd(cwd, MAX_STR_LEN - 1); 532 chdir(bkpinfo->restore_path); 533 getcwd(new, MAX_STR_LEN - 1); 534 sprintf(tmp, "new path is %s", new); 535 insist_on_this_cd_number(bkpinfo, g_current_media_number); 536 unlink("/tmp/changed.txt"); 537 538 resA = compare_all_tarballs(bkpinfo); 539 resB = compare_all_biggiefiles(bkpinfo); 540 chdir(cwd); 541 noof_changed_files = count_lines_in_file("/tmp/changed.txt"); 542 if (noof_changed_files) { 543 sprintf(tmp, "%ld files do not match the backup ", 544 noof_changed_files); 545 // mvaddstr_and_log_it( g_currentY++, 0, tmp ); 546 log_to_screen(tmp); 547 sprintf(command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE); 548 paranoid_system(command); 549 } else { 550 sprintf(tmp, "All files match the backup "); 551 mvaddstr_and_log_it(g_currentY++, 0, tmp); 552 log_to_screen(tmp); 553 } 554 555 paranoid_free(tmp); 556 paranoid_free(cwd); 557 paranoid_free(new); 558 paranoid_free(command); 559 560 return (resA + resB); 605 561 } 606 562 … … 622 578 */ 623 579 int 624 compare_mode( struct s_bkpinfo *bkpinfo,625 struct mountlist_itself *mountlist,626 580 compare_mode(struct s_bkpinfo *bkpinfo, 581 struct mountlist_itself *mountlist, 582 struct raidlist_itself *raidlist) 627 583 { 628 629 630 631 632 584 int retval = 0; 585 long q; 586 char *tmp; 587 588 malloc_string(tmp); 633 589 634 590 /************************************************************************** … … 636 592 * restore them from start of tape, if available * 637 593 **************************************************************************/ 638 assert(bkpinfo!=NULL); 639 assert(mountlist!=NULL); 640 assert(raidlist!=NULL); 641 642 while (get_cfg_file_from_archive( bkpinfo )) 643 { 644 if (!ask_me_yes_or_no("Failed to find config file/archives. Choose another source?")) 645 { fatal_error("Unable to find config file/archives. Aborting."); } 646 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 647 } 648 649 read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo ); 650 g_current_media_number = 1; 651 mvaddstr_and_log_it( 1, 30, "Comparing Automatically" ); 652 iamhere("Pre-MAD"); 653 retval = mount_all_devices( mountlist, FALSE ); 654 iamhere("Post-MAD"); 655 if ( retval ) 656 { 657 unmount_all_devices( mountlist ); 658 return( retval ); 659 } 660 if ( bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) 661 { 662 retval += compare_to_tape( bkpinfo ); 663 } 664 else if ( bkpinfo->backup_media_type == cdstream ) 665 { 666 retval += compare_to_cdstream( bkpinfo ); 667 } 668 else 669 { 670 retval += compare_to_CD( bkpinfo ); 671 } 672 if ( retval ) 673 { 674 mvaddstr_and_log_it( g_currentY++, 675 0, 676 "Warning - differences found during the compare phase"); 677 } 678 679 retval += unmount_all_devices( mountlist ); 680 681 if ( count_lines_in_file("/tmp/changed.txt") > 0 ) 682 { 683 mvaddstr_and_log_it( g_currentY++, 0, 684 "Differences found while files were being compared." ); 685 streamline_changes_file( "/tmp/changed.files", "/tmp/changed.txt" ); 686 if (count_lines_in_file( "/tmp/changed.files" ) <= 0 ) 687 { 688 mvaddstr_and_log_it( g_currentY++,0, 689 "...but they were logfiles and temporary files. Your archives are fine."); 690 log_to_screen( "The differences were logfiles and temporary files. Your archives are fine."); 691 } 692 else 693 { 694 q = count_lines_in_file("/tmp/changed.files"); 695 sprintf( tmp, "%ld significant difference%s found.", q, (q!=1) ? "s" : ""); 696 mvaddstr_and_log_it( g_currentY++, 0, tmp); 697 log_to_screen (tmp); 698 699 strcpy( tmp, "Type 'less /tmp/changed.files' for a list of non-matching files" ); 700 mvaddstr_and_log_it( g_currentY++, 0, tmp ); 701 log_to_screen( tmp ); 702 703 log_msg(2, "calling popup_changelist_from_file()"); 704 popup_changelist_from_file("/tmp/changed.files"); 705 log_msg(2, "Returning from popup_changelist_from_file()"); 706 } 707 } 708 else 709 { 710 log_to_screen( "No significant differences were found. Your backup is perfect." ); 711 } 712 kill_petris(); 713 paranoid_free(tmp); 714 return( retval ); 594 assert(bkpinfo != NULL); 595 assert(mountlist != NULL); 596 assert(raidlist != NULL); 597 598 while (get_cfg_file_from_archive(bkpinfo)) { 599 if (!ask_me_yes_or_no 600 ("Failed to find config file/archives. Choose another source?")) 601 { 602 fatal_error("Unable to find config file/archives. Aborting."); 603 } 604 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 605 } 606 607 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 608 g_current_media_number = 1; 609 mvaddstr_and_log_it(1, 30, "Comparing Automatically"); 610 iamhere("Pre-MAD"); 611 retval = mount_all_devices(mountlist, FALSE); 612 iamhere("Post-MAD"); 613 if (retval) { 614 unmount_all_devices(mountlist); 615 return (retval); 616 } 617 if (bkpinfo->backup_media_type == tape 618 || bkpinfo->backup_media_type == udev) { 619 retval += compare_to_tape(bkpinfo); 620 } else if (bkpinfo->backup_media_type == cdstream) { 621 retval += compare_to_cdstream(bkpinfo); 622 } else { 623 retval += compare_to_CD(bkpinfo); 624 } 625 if (retval) { 626 mvaddstr_and_log_it(g_currentY++, 627 0, 628 "Warning - differences found during the compare phase"); 629 } 630 631 retval += unmount_all_devices(mountlist); 632 633 if (count_lines_in_file("/tmp/changed.txt") > 0) { 634 mvaddstr_and_log_it(g_currentY++, 0, 635 "Differences found while files were being compared."); 636 streamline_changes_file("/tmp/changed.files", "/tmp/changed.txt"); 637 if (count_lines_in_file("/tmp/changed.files") <= 0) { 638 mvaddstr_and_log_it(g_currentY++, 0, 639 "...but they were logfiles and temporary files. Your archives are fine."); 640 log_to_screen 641 ("The differences were logfiles and temporary files. Your archives are fine."); 642 } else { 643 q = count_lines_in_file("/tmp/changed.files"); 644 sprintf(tmp, "%ld significant difference%s found.", q, 645 (q != 1) ? "s" : ""); 646 mvaddstr_and_log_it(g_currentY++, 0, tmp); 647 log_to_screen(tmp); 648 649 strcpy(tmp, 650 "Type 'less /tmp/changed.files' for a list of non-matching files"); 651 mvaddstr_and_log_it(g_currentY++, 0, tmp); 652 log_to_screen(tmp); 653 654 log_msg(2, "calling popup_changelist_from_file()"); 655 popup_changelist_from_file("/tmp/changed.files"); 656 log_msg(2, "Returning from popup_changelist_from_file()"); 657 } 658 } else { 659 log_to_screen 660 ("No significant differences were found. Your backup is perfect."); 661 } 662 kill_petris(); 663 paranoid_free(tmp); 664 return (retval); 715 665 } 716 666 … … 727 677 * @return 0 for success, nonzero for failure. 728 678 */ 729 int 730 compare_to_cdstream(struct s_bkpinfo *bkpinfo) 679 int compare_to_cdstream(struct s_bkpinfo *bkpinfo) 731 680 { 732 681 int res; 733 682 734 683 /** needs malloc **/ 735 char *dir, *command; 736 737 assert(bkpinfo!=NULL); 738 malloc_string(dir); 739 malloc_string(command); 740 getcwd( dir, MAX_STR_LEN ); 741 chdir( bkpinfo->restore_path ); 742 743 sprintf( command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path ); 744 run_program_and_log_output( command, FALSE ); 745 mvaddstr_and_log_it(g_currentY, 746 0, 747 "Verifying archives against filesystem" ); 748 749 if (bkpinfo->disaster_recovery && does_file_exist("/tmp/CDROM-LIVES-HERE")) 750 { strcpy(bkpinfo->media_device, last_line_of_file("/tmp/CDROM-LIVES-HERE")); } 751 else 752 { find_cdrom_device( bkpinfo->media_device, FALSE ); } 753 res = verify_tape_backups( bkpinfo ); 754 chdir( dir ); 755 if ( length_of_file ( "/tmp/changed.txt" ) > 2 && length_of_file ( "/tmp/changed.files" ) > 2 ) 756 { 757 log_msg(0, "Type 'less /tmp/changed.files' to see which files don't match the archives" ); 758 log_msg(2, "Calling popup_changelist_from_file()" ); 759 popup_changelist_from_file( "/tmp/changed.files" ); 760 log_msg(2, "Returned from popup_changelist_from_file()" ); 761 } 762 763 mvaddstr_and_log_it( g_currentY++, 74, "Done." ); 764 paranoid_free(dir); 765 paranoid_free(command); 766 return( res ); 684 char *dir, *command; 685 686 assert(bkpinfo != NULL); 687 malloc_string(dir); 688 malloc_string(command); 689 getcwd(dir, MAX_STR_LEN); 690 chdir(bkpinfo->restore_path); 691 692 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 693 bkpinfo->restore_path); 694 run_program_and_log_output(command, FALSE); 695 mvaddstr_and_log_it(g_currentY, 696 0, "Verifying archives against filesystem"); 697 698 if (bkpinfo->disaster_recovery 699 && does_file_exist("/tmp/CDROM-LIVES-HERE")) { 700 strcpy(bkpinfo->media_device, 701 last_line_of_file("/tmp/CDROM-LIVES-HERE")); 702 } else { 703 find_cdrom_device(bkpinfo->media_device, FALSE); 704 } 705 res = verify_tape_backups(bkpinfo); 706 chdir(dir); 707 if (length_of_file("/tmp/changed.txt") > 2 708 && length_of_file("/tmp/changed.files") > 2) { 709 log_msg(0, 710 "Type 'less /tmp/changed.files' to see which files don't match the archives"); 711 log_msg(2, "Calling popup_changelist_from_file()"); 712 popup_changelist_from_file("/tmp/changed.files"); 713 log_msg(2, "Returned from popup_changelist_from_file()"); 714 } 715 716 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 717 paranoid_free(dir); 718 paranoid_free(command); 719 return (res); 767 720 } 721 768 722 /************************************************************************** 769 723 *END_COMPARE_CD_STREAM * … … 782 736 * returns: int * 783 737 **************************************************************************/ 784 int 785 compare_to_tape( struct s_bkpinfo *bkpinfo ) 738 int compare_to_tape(struct s_bkpinfo *bkpinfo) 786 739 { 787 int res; 788 char *dir, *command; 789 790 assert(bkpinfo!=NULL); 791 malloc_string(dir); 792 malloc_string(command); 793 794 getcwd( dir, MAX_STR_LEN ); 795 chdir( bkpinfo->restore_path ); 796 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path); 797 run_program_and_log_output( command, FALSE ); 798 mvaddstr_and_log_it( g_currentY, 799 0, 800 "Verifying archives against filesystem"); 801 res = verify_tape_backups( bkpinfo ); 802 chdir( dir ); 803 if ( res ) 804 { 805 mvaddstr_and_log_it( g_currentY++, 74, "Failed." ); 806 } 807 else 808 { 809 mvaddstr_and_log_it( g_currentY++, 74, "Done." ); 810 } 811 paranoid_free(dir); 812 paranoid_free(command); 813 return( res ); 740 int res; 741 char *dir, *command; 742 743 assert(bkpinfo != NULL); 744 malloc_string(dir); 745 malloc_string(command); 746 747 getcwd(dir, MAX_STR_LEN); 748 chdir(bkpinfo->restore_path); 749 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 750 bkpinfo->restore_path); 751 run_program_and_log_output(command, FALSE); 752 mvaddstr_and_log_it(g_currentY, 753 0, "Verifying archives against filesystem"); 754 res = verify_tape_backups(bkpinfo); 755 chdir(dir); 756 if (res) { 757 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 758 } else { 759 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 760 } 761 paranoid_free(dir); 762 paranoid_free(command); 763 return (res); 814 764 } 815 765 … … 819 769 820 770 /* @} - end compareGroup */ 821 -
trunk/mondo/mondo/mondorestore/mondo-rstr-compare.h
r30 r59 1 1 /* mondo-rstr-compare.h 2 * $Id : mondo-rstr-compare.h,v 1.1 2004/06/10 15:29:13 hugo Exp$2 * $Id$ 3 3 */ 4 4 5 5 6 int compare_to_CD(struct s_bkpinfo *);7 int compare_to_cdstream(struct s_bkpinfo *);8 int compare_to_tape(struct s_bkpinfo *);6 int compare_to_CD(struct s_bkpinfo *); 7 int compare_to_cdstream(struct s_bkpinfo *); 8 int compare_to_tape(struct s_bkpinfo *); 9 9 10 int 11 compare_mode( struct s_bkpinfo *bkpinfo,12 struct mountlist_itself *mountlist,13 10 int 11 compare_mode(struct s_bkpinfo *bkpinfo, 12 struct mountlist_itself *mountlist, 13 struct raidlist_itself *raidlist); -
trunk/mondo/mondo/mondorestore/mondo-rstr-newt.c
r30 r59 8 8 edited by : by Stan Benoit 4/2002 9 9 email : troff@nakedsoul.org 10 cvsid : $Id : mondo-rstr-newt.c,v 1.5 2004/06/10 15:29:13 hugo Exp$10 cvsid : $Id$ 11 11 ***************************************************************************/ 12 12 … … 92 92 #include "mondo-rstr-newt.h" 93 93 94 //static char cvsid[] = "$Id : mondo-rstr-newt.c,v 1.5 2004/06/10 15:29:13 hugo Exp$";94 //static char cvsid[] = "$Id$"; 95 95 96 96 extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN]; … … 127 127 */ 128 128 void 129 add_disklist_entry 130 129 add_disklist_entry(struct list_of_disks *disklist, char *raid_device, 130 struct mountlist_itself *unallocated_raid_partitions) 131 131 { 132 132 /** buffers ***********************************************************/ 133 133 char tmp[MAX_STR_LEN]; 134 134 135 135 /** newt **************************************************************/ 136 136 newtComponent myForm; 137 137 newtComponent bOK; 138 138 newtComponent bCancel; … … 140 140 newtComponent partitionsListbox; 141 141 newtComponent headerMsg; 142 142 143 143 /** prototypes *********************************************************/ 144 145 144 void *keylist[ARBITRARY_MAXIMUM]; 145 void *curr_choice; 146 146 147 147 /** int ****************************************************************/ 148 148 int i = 0; 149 149 int index = 0; 150 150 int currline = 0; 151 151 int items = 0; 152 152 153 assert(disklist!=NULL); 154 assert_string_is_neither_NULL_nor_zerolength(raid_device); 155 assert(unallocated_raid_partitions!=NULL); 156 157 newtPushHelpLine 158 (" Add one of the following unallocated RAID partitions to this RAID device."); 159 sprintf (tmp, "%-26s %s", "Device", "Size"); 160 headerMsg = newtLabel (1, 1, tmp); 161 partitionsListbox = 162 newtListbox (1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 163 redraw_unallocpartnslist (unallocated_raid_partitions, keylist, 164 partitionsListbox); 165 i = 7; 166 bOK = newtCompactButton (i, 9, " OK "); 167 bCancel = newtCompactButton (i += 9, 9, "Cancel"); 168 newtOpenWindow (22, 6, 36, 10, "Unallocated RAID partitions"); 169 myForm = newtForm (NULL, NULL, 0); 170 newtFormAddComponents (myForm, headerMsg, partitionsListbox, bOK, bCancel, 171 NULL); 172 b_res = newtRunForm (myForm); 173 if (b_res != bCancel) 174 { 175 curr_choice = newtListboxGetCurrent (partitionsListbox); 176 for (currline = 0; 177 currline < unallocated_raid_partitions->entries 178 && keylist[currline] != curr_choice; currline++); 179 if (currline == unallocated_raid_partitions->entries 180 && unallocated_raid_partitions->entries > 0) 181 { 182 log_it ("I don't know what this button does"); 183 } 184 else 185 { 186 index = find_next_free_index_in_disklist (disklist); 187 188 items = disklist->entries; 189 strcpy (disklist->el[items].device, 190 unallocated_raid_partitions->el[currline].device); 191 disklist->el[items].index = index; 192 disklist->entries = ++items; 193 194 } 195 } 196 newtFormDestroy (myForm); 197 newtPopWindow (); 198 newtPopHelpLine (); 153 assert(disklist != NULL); 154 assert_string_is_neither_NULL_nor_zerolength(raid_device); 155 assert(unallocated_raid_partitions != NULL); 156 157 newtPushHelpLine 158 (" Add one of the following unallocated RAID partitions to this RAID device."); 159 sprintf(tmp, "%-26s %s", "Device", "Size"); 160 headerMsg = newtLabel(1, 1, tmp); 161 partitionsListbox = 162 newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 163 redraw_unallocpartnslist(unallocated_raid_partitions, keylist, 164 partitionsListbox); 165 i = 7; 166 bOK = newtCompactButton(i, 9, " OK "); 167 bCancel = newtCompactButton(i += 9, 9, "Cancel"); 168 newtOpenWindow(22, 6, 36, 10, "Unallocated RAID partitions"); 169 myForm = newtForm(NULL, NULL, 0); 170 newtFormAddComponents(myForm, headerMsg, partitionsListbox, bOK, 171 bCancel, NULL); 172 b_res = newtRunForm(myForm); 173 if (b_res != bCancel) { 174 curr_choice = newtListboxGetCurrent(partitionsListbox); 175 for (currline = 0; 176 currline < unallocated_raid_partitions->entries 177 && keylist[currline] != curr_choice; currline++); 178 if (currline == unallocated_raid_partitions->entries 179 && unallocated_raid_partitions->entries > 0) { 180 log_it("I don't know what this button does"); 181 } else { 182 index = find_next_free_index_in_disklist(disklist); 183 184 items = disklist->entries; 185 strcpy(disklist->el[items].device, 186 unallocated_raid_partitions->el[currline].device); 187 disklist->el[items].index = index; 188 disklist->entries = ++items; 189 190 } 191 } 192 newtFormDestroy(myForm); 193 newtPopWindow(); 194 newtPopHelpLine(); 199 195 } 200 196 … … 212 208 */ 213 209 void 214 add_mountlist_entry 215 struct raidlist_itself *raidlist, newtComponent listbox,216 210 add_mountlist_entry(struct mountlist_itself *mountlist, 211 struct raidlist_itself *raidlist, 212 newtComponent listbox, int currline, void *keylist[]) 217 213 { 218 214 219 215 /** int **************************************************************/ 220 int i= 0;216 int i = 0; 221 217 int num_to_add = 0; 222 218 223 219 /** newt *************************************************************/ 224 220 newtComponent myForm; 225 221 newtComponent bOK; 226 222 newtComponent bCancel; … … 236 232 237 233 /** buffers **********************************************************/ 238 234 char drive_to_add[MAX_STR_LEN]; 239 235 char mountpoint_str[MAX_STR_LEN]; 240 236 char size_str[MAX_STR_LEN]; 241 237 char device_str[MAX_STR_LEN]; 242 238 char format_str[MAX_STR_LEN]; 243 239 … … 248 244 char *format_here; 249 245 250 assert(mountlist!=NULL);251 assert(raidlist!=NULL);252 assert(listbox!=NULL);253 assert(keylist!=NULL);254 255 strcpy 256 strcpy 246 assert(mountlist != NULL); 247 assert(raidlist != NULL); 248 assert(listbox != NULL); 249 assert(keylist != NULL); 250 251 strcpy(device_str, "/dev/"); 252 strcpy(mountpoint_str, "/"); 257 253 #ifdef __FreeBSD__ 258 strcpy 254 strcpy(format_str, "ufs"); 259 255 #else 260 strcpy(format_str, "ext2");256 strcpy(format_str, "ext2"); 261 257 #endif 262 size_str[0] = '\0'; 263 /* sprintf(size_str,""); */ 264 newtOpenWindow (20, 5, 48, 10, "Add entry"); 265 label0 = newtLabel (2, 1, "Device: "); 266 label1 = newtLabel (2, 2, "Mountpoint:"); 267 label2 = newtLabel (2, 3, "Size (MB): "); 268 label3 = newtLabel (2, 4, "Format: "); 269 deviceComp = newtEntry (14, 1, device_str, 30, (void*)&device_here, 0); 270 mountpointComp = newtEntry (14, 2, mountpoint_str, 30, (void*)&mountpoint_here, 0); 271 formatComp = newtEntry (14, 4, format_str, 15, (void*)&format_here, 0); 272 sizeComp = newtEntry (14, 3, size_str, 10, (void*)&size_here, 0); 273 bOK = newtButton (5, 6, " OK "); 274 bCancel = newtButton (17, 6, "Cancel"); 275 newtPushHelpLine 276 ("To add an entry to the mountlist, please fill in these fields and then hit 'OK'"); 277 myForm = newtForm (NULL, NULL, 0); 278 newtFormAddComponents (myForm, deviceComp, mountpointComp, sizeComp, 279 formatComp, label0, label1, label2, label3, bOK, 280 bCancel, NULL); 281 for (b_res = NULL; b_res != bOK && b_res != bCancel;) 282 { 283 b_res = newtRunForm (myForm); 284 strcpy (device_str, device_here); 285 strcpy (mountpoint_str, mountpoint_here); 286 strcpy (format_str, format_here); 287 strcpy (size_str, size_here); 258 size_str[0] = '\0'; 259 /* sprintf(size_str,""); */ 260 newtOpenWindow(20, 5, 48, 10, "Add entry"); 261 label0 = newtLabel(2, 1, "Device: "); 262 label1 = newtLabel(2, 2, "Mountpoint:"); 263 label2 = newtLabel(2, 3, "Size (MB): "); 264 label3 = newtLabel(2, 4, "Format: "); 265 deviceComp = 266 newtEntry(14, 1, device_str, 30, (void *) &device_here, 0); 267 mountpointComp = 268 newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0); 269 formatComp = 270 newtEntry(14, 4, format_str, 15, (void *) &format_here, 0); 271 sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0); 272 bOK = newtButton(5, 6, " OK "); 273 bCancel = newtButton(17, 6, "Cancel"); 274 newtPushHelpLine 275 ("To add an entry to the mountlist, please fill in these fields and then hit 'OK'"); 276 myForm = newtForm(NULL, NULL, 0); 277 newtFormAddComponents(myForm, deviceComp, mountpointComp, sizeComp, 278 formatComp, label0, label1, label2, label3, bOK, 279 bCancel, NULL); 280 for (b_res = NULL; b_res != bOK && b_res != bCancel;) { 281 b_res = newtRunForm(myForm); 282 strcpy(device_str, device_here); 283 strcpy(mountpoint_str, mountpoint_here); 284 strcpy(format_str, format_here); 285 strcpy(size_str, size_here); 288 286 // log_it ("Originals = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str); 289 strip_spaces(device_str);290 strip_spaces(mountpoint_str);291 strip_spaces(format_str);292 strip_spaces(size_str);287 strip_spaces(device_str); 288 strip_spaces(mountpoint_str); 289 strip_spaces(format_str); 290 strip_spaces(size_str); 293 291 // log_it ("Modified = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str); 294 if (b_res == bOK) 295 { 296 if (device_str[strlen (device_str) - 1] == '/') 297 { 298 popup_and_OK ("You left the device nearly blank!"); 299 b_res = NULL; 300 } 301 if (size_of_specific_device_in_mountlist (mountlist, device_str) >= 0) 302 { 303 popup_and_OK ("Can't add this - you've got one already!"); 304 b_res = NULL; 305 } 306 } 307 } 308 newtFormDestroy (myForm); 309 newtPopHelpLine (); 310 newtPopWindow (); 311 if (b_res == bCancel) 312 { 313 return; 314 } 315 strcpy (drive_to_add, device_str); 316 for (i = strlen (drive_to_add); isdigit (drive_to_add[i - 1]); i--); 317 num_to_add = atoi (drive_to_add + i); 318 drive_to_add[i] = '\0'; 319 currline = mountlist->entries; 320 strcpy (mountlist->el[currline].device, device_str); 321 strcpy (mountlist->el[currline].mountpoint, mountpoint_str); 322 strcpy (mountlist->el[currline].format, format_str); 323 mountlist->el[currline].size = atol (size_str) * 1024; 324 mountlist->entries++; 325 if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB)) 326 { 327 initiate_new_raidlist_entry (raidlist, mountlist, currline, device_str); 328 } 329 redraw_mountlist (mountlist, keylist, listbox); 292 if (b_res == bOK) { 293 if (device_str[strlen(device_str) - 1] == '/') { 294 popup_and_OK("You left the device nearly blank!"); 295 b_res = NULL; 296 } 297 if (size_of_specific_device_in_mountlist(mountlist, device_str) 298 >= 0) { 299 popup_and_OK("Can't add this - you've got one already!"); 300 b_res = NULL; 301 } 302 } 303 } 304 newtFormDestroy(myForm); 305 newtPopHelpLine(); 306 newtPopWindow(); 307 if (b_res == bCancel) { 308 return; 309 } 310 strcpy(drive_to_add, device_str); 311 for (i = strlen(drive_to_add); isdigit(drive_to_add[i - 1]); i--); 312 num_to_add = atoi(drive_to_add + i); 313 drive_to_add[i] = '\0'; 314 currline = mountlist->entries; 315 strcpy(mountlist->el[currline].device, device_str); 316 strcpy(mountlist->el[currline].mountpoint, mountpoint_str); 317 strcpy(mountlist->el[currline].format, format_str); 318 mountlist->el[currline].size = atol(size_str) * 1024; 319 mountlist->entries++; 320 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) { 321 initiate_new_raidlist_entry(raidlist, mountlist, currline, 322 device_str); 323 } 324 redraw_mountlist(mountlist, keylist, listbox); 330 325 } 331 326 … … 337 332 * @ingroup restoreGuiVarslist 338 333 */ 339 void 340 add_varslist_entry (struct raid_device_record *raidrec) 334 void add_varslist_entry(struct raid_device_record *raidrec) 341 335 { 342 336 343 337 /** buffers ***********************************************************/ 344 338 char sz_out[MAX_STR_LEN]; 345 339 346 340 /** int ****************************************************************/ 347 int items= 0;341 int items = 0; 348 342 int i = 0; 349 343 350 assert(raidrec!=NULL); 351 352 sz_out[0] = '\0'; 353 if (popup_and_get_string 354 ("Add variable", "Enter the name of the variable to add", sz_out, MAX_STR_LEN)) 355 { 356 strip_spaces (sz_out); 357 items = raidrec->additional_vars.entries; 358 for (i = 0; 359 i < items && strcmp (raidrec->additional_vars.el[i].label, sz_out); 360 i++); 361 if (i < items) 362 { 363 popup_and_OK 364 ("No need to add that variable. It is already listed here."); 365 } 366 else 367 { 368 strcpy (raidrec->additional_vars.el[items].label, sz_out); 369 edit_varslist_entry (raidrec, items); 370 raidrec->additional_vars.entries = ++items; 371 } 372 } 344 assert(raidrec != NULL); 345 346 sz_out[0] = '\0'; 347 if (popup_and_get_string 348 ("Add variable", "Enter the name of the variable to add", sz_out, 349 MAX_STR_LEN)) { 350 strip_spaces(sz_out); 351 items = raidrec->additional_vars.entries; 352 for (i = 0; 353 i < items 354 && strcmp(raidrec->additional_vars.el[i].label, sz_out); i++); 355 if (i < items) { 356 popup_and_OK 357 ("No need to add that variable. It is already listed here."); 358 } else { 359 strcpy(raidrec->additional_vars.el[items].label, sz_out); 360 edit_varslist_entry(raidrec, items); 361 raidrec->additional_vars.entries = ++items; 362 } 363 } 373 364 } 374 365 #endif … … 383 374 */ 384 375 long 385 calculate_raid_device_size 386 387 376 calculate_raid_device_size(struct mountlist_itself *mountlist, 377 struct raidlist_itself *raidlist, 378 char *raid_device) 388 379 { 389 380 #ifdef __FreeBSD__ 390 381 /** FreeBSD-specific version of calculate_raid_device_size() **/ 391 382 392 383 /** structures ********************************************************/ 393 384 struct vinum_volume *raidrec; 394 385 395 386 /** int ***************************************************************/ 396 387 int i = 0, j = 0; 397 388 int noof_partitions = 0; 398 389 399 390 /** long **************************************************************/ 400 401 402 403 long smallest_plex= 999999999;391 long total_size = 0; 392 long plex_size = 0; 393 long smallest_partition = 999999999; 394 long smallest_plex = 999999999; 404 395 long sp = 0; 405 396 406 397 /** buffers ***********************************************************/ 407 char tmp[MAX_STR_LEN]; 408 409 410 411 412 for (i = 0; 413 i < raidlist->entries 414 && strcmp (raidlist->el[i].volname, basename (raid_device)); i++); 415 if (i == raidlist->entries) 416 { 417 sprintf (tmp, 418 "Cannot calc size of raid device %s - cannot find it in raidlist", 419 raid_device); 420 log_it (tmp); 421 return (0); // Isn't this more sensible than 999999999? If the raid dev !exists, 422 // then it has no size, right? 423 } 424 raidrec = &raidlist->el[i]; 425 total_size = 0; 426 if (raidrec->plexes == 0) return 0; 427 for (j = 0; j < raidrec->plexes; j++) { 428 plex_size = 0; 429 int k = 0, l = 0; 430 for (k = 0; k < raidrec->plex[j].subdisks; ++k) { 431 char devname[64]; 432 strcpy (devname, raidrec->plex[j].sd[k].which_device); 433 for (l = 0; l < raidlist->disks.entries; ++l) { 434 if (!strcmp (devname, raidlist->disks.el[l].name)) { 435 switch (raidrec->plex[j].raidlevel) { 436 case -1: 437 plex_size += 438 size_of_specific_device_in_mountlist (mountlist, 439 raidlist->disks.el[l].device); 440 break; 441 case 0: 442 case 5: 443 if (size_of_specific_device_in_mountlist (mountlist, 444 raidlist->disks.el[l].device) < smallest_partition) { 445 smallest_partition = size_of_specific_device_in_mountlist (mountlist, 446 raidlist->disks.el[l].device); 447 } 448 break; 449 } 450 } 451 } 452 } 453 454 if (!is_this_raid_personality_registered (raidrec->plex[j].raidlevel)) { 455 log_it ("%s has a really weird RAID level - couldn't calc size :(", raid_device); 456 return (999999999); 457 } 458 if (raidrec->plex[j].raidlevel != -1) { 459 plex_size = smallest_partition * (raidrec->plex[j].subdisks - 460 (raidrec->plex[j].raidlevel == 5 ? 1 : 0)); 461 } 462 if (plex_size < smallest_plex) 463 smallest_plex = plex_size; 464 465 smallest_partition = 999999999; 466 } 467 468 sprintf (tmp, "I have calculated %s's real size to be %ld", raid_device, 469 (long) smallest_plex); 470 log_it (tmp); 471 return (smallest_plex); 398 char tmp[MAX_STR_LEN]; 399 400 401 402 403 for (i = 0; 404 i < raidlist->entries 405 && strcmp(raidlist->el[i].volname, basename(raid_device)); i++); 406 if (i == raidlist->entries) { 407 sprintf(tmp, 408 "Cannot calc size of raid device %s - cannot find it in raidlist", 409 raid_device); 410 log_it(tmp); 411 return (0); // Isn't this more sensible than 999999999? If the raid dev !exists, 412 // then it has no size, right? 413 } 414 raidrec = &raidlist->el[i]; 415 total_size = 0; 416 if (raidrec->plexes == 0) 417 return 0; 418 for (j = 0; j < raidrec->plexes; j++) { 419 plex_size = 0; 420 int k = 0, l = 0; 421 for (k = 0; k < raidrec->plex[j].subdisks; ++k) { 422 char devname[64]; 423 strcpy(devname, raidrec->plex[j].sd[k].which_device); 424 for (l = 0; l < raidlist->disks.entries; ++l) { 425 if (!strcmp(devname, raidlist->disks.el[l].name)) { 426 switch (raidrec->plex[j].raidlevel) { 427 case -1: 428 plex_size += 429 size_of_specific_device_in_mountlist(mountlist, 430 raidlist-> 431 disks. 432 el[l]. 433 device); 434 break; 435 case 0: 436 case 5: 437 if (size_of_specific_device_in_mountlist(mountlist, 438 raidlist-> 439 disks. 440 el[l]. 441 device) < 442 smallest_partition) { 443 smallest_partition = 444 size_of_specific_device_in_mountlist 445 (mountlist, raidlist->disks.el[l].device); 446 } 447 break; 448 } 449 } 450 } 451 } 452 453 if (!is_this_raid_personality_registered 454 (raidrec->plex[j].raidlevel)) { 455 log_it 456 ("%s has a really weird RAID level - couldn't calc size :(", 457 raid_device); 458 return (999999999); 459 } 460 if (raidrec->plex[j].raidlevel != -1) { 461 plex_size = smallest_partition * (raidrec->plex[j].subdisks - 462 (raidrec->plex[j]. 463 raidlevel == 5 ? 1 : 0)); 464 } 465 if (plex_size < smallest_plex) 466 smallest_plex = plex_size; 467 468 smallest_partition = 999999999; 469 } 470 471 sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device, 472 (long) smallest_plex); 473 log_it(tmp); 474 return (smallest_plex); 472 475 #else 473 476 /** Linux-specific version of calculate_raid_device_size() **/ 474 477 475 478 /** structures ********************************************************/ 476 479 struct raid_device_record *raidrec; 477 480 478 481 /** int ***************************************************************/ 479 482 int i = 0; 480 483 int noof_partitions = 0; 481 484 482 485 /** long **************************************************************/ 483 486 long total_size = 0; 484 487 long smallest_partition = 999999999; 485 488 long sp = 0; 486 489 487 490 /** buffers ***********************************************************/ 488 char tmp[MAX_STR_LEN]; 489 490 assert(mountlist!=NULL); 491 assert(raidlist!=NULL); 492 assert_string_is_neither_NULL_nor_zerolength(raid_device); 493 494 for (i = 0; 495 i < raidlist->entries 496 && strcmp (raidlist->el[i].raid_device, raid_device); i++); 497 if (i == raidlist->entries) 498 { 499 sprintf (tmp, 500 "Cannot calc size of raid device %s - cannot find it in raidlist", 501 raid_device); 502 log_it (tmp); 503 return (999999999); 504 } 505 raidrec = &raidlist->el[i]; 506 noof_partitions = raidrec->data_disks.entries; 507 if (raidrec->raid_level == -1 || raidrec->raid_level == 0) 508 { 509 for (total_size = 0, i = 0; i < noof_partitions; i++) 510 { 511 total_size += 512 size_of_specific_device_in_mountlist (mountlist, 513 raidrec->data_disks.el[i].device); 514 } 515 } 516 else 517 { 518 for (i = 0; i < noof_partitions; i++) 519 { 520 sp = 521 size_of_specific_device_in_mountlist (mountlist, 522 raidrec->data_disks.el[i].device); 523 if (smallest_partition > sp) 524 { 525 smallest_partition = sp; 526 } 527 } 528 total_size = smallest_partition * (noof_partitions - 1); 529 } 530 sprintf (tmp, "I have calculated %s's real size to be %ld", raid_device, 531 (long) total_size); 532 log_it (tmp); 533 return (total_size); 491 char tmp[MAX_STR_LEN]; 492 493 assert(mountlist != NULL); 494 assert(raidlist != NULL); 495 assert_string_is_neither_NULL_nor_zerolength(raid_device); 496 497 for (i = 0; 498 i < raidlist->entries 499 && strcmp(raidlist->el[i].raid_device, raid_device); i++); 500 if (i == raidlist->entries) { 501 sprintf(tmp, 502 "Cannot calc size of raid device %s - cannot find it in raidlist", 503 raid_device); 504 log_it(tmp); 505 return (999999999); 506 } 507 raidrec = &raidlist->el[i]; 508 noof_partitions = raidrec->data_disks.entries; 509 if (raidrec->raid_level == -1 || raidrec->raid_level == 0) { 510 for (total_size = 0, i = 0; i < noof_partitions; i++) { 511 total_size += 512 size_of_specific_device_in_mountlist(mountlist, 513 raidrec->data_disks. 514 el[i].device); 515 } 516 } else { 517 for (i = 0; i < noof_partitions; i++) { 518 sp = size_of_specific_device_in_mountlist(mountlist, 519 raidrec->data_disks. 520 el[i].device); 521 if (smallest_partition > sp) { 522 smallest_partition = sp; 523 } 524 } 525 total_size = smallest_partition * (noof_partitions - 1); 526 } 527 sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device, 528 (long) total_size); 529 log_it(tmp); 530 return (total_size); 534 531 #endif 535 532 } … … 543 540 */ 544 541 void 545 choose_raid_level (struct OSSWAP (raid_device_record, vinum_plex) *raidrec)542 choose_raid_level(struct OSSWAP (raid_device_record, vinum_plex) * raidrec) 546 543 { 547 544 548 545 #ifdef __FreeBSD__ 549 546 550 547 /** int ***************************************************************/ 551 548 int res = 0; 552 549 int out = 0; 553 550 554 551 /** buffers ***********************************************************/ 555 char tmp[MAX_STR_LEN]; 556 char prompt[MAX_STR_LEN]; 557 char sz[MAX_STR_LEN]; 558 559 sprintf (prompt, "Please enter the RAID level you want. (concat, striped, raid5)"); 560 if (raidrec->raidlevel == -1) 561 { 562 strcpy (tmp, "concat"); 563 } 564 else if (raidrec->raidlevel == 0) 565 { 566 strcpy (tmp, "striped"); 567 } else { 568 sprintf (tmp, "raid%i", raidrec->raidlevel); 569 } 570 for (out = 999; out == 999;) 571 { 572 res = popup_and_get_string ("Specify RAID level", prompt, tmp, 10); 573 if (!res) 574 { 575 return; 576 } 577 strip_spaces (tmp); 578 if (tmp[0] == '[' && tmp[strlen (tmp) - 1] == ']') 579 { 580 strcpy (sz, tmp); 581 strncpy (tmp, sz + 1, strlen (sz) - 2); 582 tmp[strlen (sz) - 2] = '\0'; 583 } 584 if (!strcmp (tmp, "concat")) 585 { 586 out = -1; 587 } 588 else if (!strcmp (tmp, "striped")) 589 { 590 out = 0; 591 } 592 else if (!strcmp (tmp, "raid5")) 593 { 594 out = 5; 595 } 596 log_it (tmp); 597 if (is_this_raid_personality_registered (out)) 598 { 599 log_it 600 ("Groovy. You've picked a RAID personality which is registered."); 601 } 602 else 603 { 604 if (ask_me_yes_or_no 605 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 606 { 607 out = 999; 608 } 609 } 610 } 611 raidrec->raidlevel = out; 552 char tmp[MAX_STR_LEN]; 553 char prompt[MAX_STR_LEN]; 554 char sz[MAX_STR_LEN]; 555 556 sprintf(prompt, 557 "Please enter the RAID level you want. (concat, striped, raid5)"); 558 if (raidrec->raidlevel == -1) { 559 strcpy(tmp, "concat"); 560 } else if (raidrec->raidlevel == 0) { 561 strcpy(tmp, "striped"); 562 } else { 563 sprintf(tmp, "raid%i", raidrec->raidlevel); 564 } 565 for (out = 999; out == 999;) { 566 res = popup_and_get_string("Specify RAID level", prompt, tmp, 10); 567 if (!res) { 568 return; 569 } 570 strip_spaces(tmp); 571 if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') { 572 strcpy(sz, tmp); 573 strncpy(tmp, sz + 1, strlen(sz) - 2); 574 tmp[strlen(sz) - 2] = '\0'; 575 } 576 if (!strcmp(tmp, "concat")) { 577 out = -1; 578 } else if (!strcmp(tmp, "striped")) { 579 out = 0; 580 } else if (!strcmp(tmp, "raid5")) { 581 out = 5; 582 } 583 log_it(tmp); 584 if (is_this_raid_personality_registered(out)) { 585 log_it 586 ("Groovy. You've picked a RAID personality which is registered."); 587 } else { 588 if (ask_me_yes_or_no 589 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 590 { 591 out = 999; 592 } 593 } 594 } 595 raidrec->raidlevel = out; 612 596 #else 613 597 /** buffers ***********************************************************/ 614 598 char tmp[MAX_STR_LEN]; 615 599 char personalities[MAX_STR_LEN]; 616 600 char prompt[MAX_STR_LEN]; 617 601 char sz[MAX_STR_LEN]; 618 int out=0, res=0; 619 620 621 assert(raidrec!=NULL); 622 system 623 ("cat /proc/mdstat | grep Pers > /tmp/raid-personalities.txt 2> /dev/null"); 624 strcpy (personalities, last_line_of_file ("/tmp/raid-personalities.txt")); 625 sprintf (prompt, "Please enter the RAID level you want. %s", personalities); 626 if (raidrec->raid_level == -1) 627 { 628 strcpy (tmp, "linear"); 629 } 630 else 631 { 632 sprintf (tmp, "%d", raidrec->raid_level); 633 } 634 for (out = 999; 635 out != -1 && out != 0 && out != 1 && out != 4 && out != 5 636 && out != 10;) 637 { 638 res = popup_and_get_string ("Specify RAID level", prompt, tmp, 10); 639 if (!res) 640 { 641 return; 642 } 643 strip_spaces (tmp); 644 if (tmp[0] == '[' && tmp[strlen (tmp) - 1] == ']') 645 { 646 strcpy (sz, tmp); 647 strncpy (tmp, sz + 1, strlen (sz) - 2); 648 tmp[strlen (sz) - 2] = '\0'; 649 } 650 if (!strcmp (tmp, "linear")) 651 { 652 out = -1; 653 } 654 else if (!strncmp (tmp, "raid", 4)) 655 { 656 out = atoi (tmp + 4); 657 } 658 else 659 { 660 out = atoi (tmp); 661 } 662 log_it (tmp); 663 if (is_this_raid_personality_registered (out)) 664 { 665 log_it 666 ("Groovy. You've picked a RAID personality which is registered."); 667 } 668 else 669 { 670 if (ask_me_yes_or_no 671 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 672 { 673 out = 999; 674 } 675 } 676 } 677 raidrec->raid_level = out; 602 int out = 0, res = 0; 603 604 605 assert(raidrec != NULL); 606 system 607 ("cat /proc/mdstat | grep Pers > /tmp/raid-personalities.txt 2> /dev/null"); 608 strcpy(personalities, 609 last_line_of_file("/tmp/raid-personalities.txt")); 610 sprintf(prompt, "Please enter the RAID level you want. %s", 611 personalities); 612 if (raidrec->raid_level == -1) { 613 strcpy(tmp, "linear"); 614 } else { 615 sprintf(tmp, "%d", raidrec->raid_level); 616 } 617 for (out = 999; 618 out != -1 && out != 0 && out != 1 && out != 4 && out != 5 619 && out != 10;) { 620 res = popup_and_get_string("Specify RAID level", prompt, tmp, 10); 621 if (!res) { 622 return; 623 } 624 strip_spaces(tmp); 625 if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') { 626 strcpy(sz, tmp); 627 strncpy(tmp, sz + 1, strlen(sz) - 2); 628 tmp[strlen(sz) - 2] = '\0'; 629 } 630 if (!strcmp(tmp, "linear")) { 631 out = -1; 632 } else if (!strncmp(tmp, "raid", 4)) { 633 out = atoi(tmp + 4); 634 } else { 635 out = atoi(tmp); 636 } 637 log_it(tmp); 638 if (is_this_raid_personality_registered(out)) { 639 log_it 640 ("Groovy. You've picked a RAID personality which is registered."); 641 } else { 642 if (ask_me_yes_or_no 643 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 644 { 645 out = 999; 646 } 647 } 648 } 649 raidrec->raid_level = out; 678 650 #endif 679 651 } … … 690 662 */ 691 663 void 692 del_partns_listed_in_disklist 693 694 664 del_partns_listed_in_disklist(struct mountlist_itself *mountlist, 665 struct raidlist_itself *raidlist, 666 struct list_of_disks *disklist) 695 667 { 696 668 697 669 /** int ***************************************************************/ 698 670 int i = 0; 699 671 int pos = 0; 700 672 701 673 /** buffers ***********************************************************/ 702 char tmp[MAX_STR_LEN]; 703 704 assert(mountlist!=NULL); 705 assert(raidlist!=NULL); 706 assert(disklist!=NULL); 707 708 for (i = 0; i < disklist->entries; i++) 709 { 710 for (pos = 0; 711 pos < mountlist->entries 712 && strcmp (mountlist->el[pos].device, disklist->el[i].device); 713 pos++); 714 if (pos < mountlist->entries) 715 { 716 sprintf (tmp, 717 "Deleting partition %s cos it was part of a now-defunct RAID", 718 mountlist->el[pos].device); 719 log_it (tmp); 720 memcpy ((void *) &mountlist->el[pos], 721 (void *) &mountlist->el[mountlist->entries - 1], 722 sizeof (struct mountlist_line)); 723 mountlist->entries--; 724 } 725 } 674 char tmp[MAX_STR_LEN]; 675 676 assert(mountlist != NULL); 677 assert(raidlist != NULL); 678 assert(disklist != NULL); 679 680 for (i = 0; i < disklist->entries; i++) { 681 for (pos = 0; 682 pos < mountlist->entries 683 && strcmp(mountlist->el[pos].device, disklist->el[i].device); 684 pos++); 685 if (pos < mountlist->entries) { 686 sprintf(tmp, 687 "Deleting partition %s cos it was part of a now-defunct RAID", 688 mountlist->el[pos].device); 689 log_it(tmp); 690 memcpy((void *) &mountlist->el[pos], 691 (void *) &mountlist->el[mountlist->entries - 1], 692 sizeof(struct mountlist_line)); 693 mountlist->entries--; 694 } 695 } 726 696 } 727 697 … … 737 707 */ 738 708 void 739 delete_disklist_entry 740 709 delete_disklist_entry(struct list_of_disks *disklist, char *raid_device, 710 int currline) 741 711 { 742 712 743 713 /** int ***************************************************************/ 744 714 int pos = 0; 745 715 746 716 /** buffers ***********************************************************/ 747 char tmp[MAX_STR_LEN]; 748 749 assert(disklist!=NULL); 750 assert_string_is_neither_NULL_nor_zerolength(raid_device); 751 752 sprintf (tmp, "Delete %s from RAID device %s - are you sure?", 753 disklist->el[currline].device, raid_device); 754 if (!ask_me_yes_or_no (tmp)) 755 { 756 return; 757 } 758 for (pos = currline; pos < disklist->entries - 1; pos++) 759 { 760 /* memcpy((void*)&disklist->el[pos], (void*)&disklist->el[pos+1], sizeof(struct s_disk)); */ 761 strcpy (disklist->el[pos].device, disklist->el[pos + 1].device); 762 } 763 disklist->entries--; 717 char tmp[MAX_STR_LEN]; 718 719 assert(disklist != NULL); 720 assert_string_is_neither_NULL_nor_zerolength(raid_device); 721 722 sprintf(tmp, "Delete %s from RAID device %s - are you sure?", 723 disklist->el[currline].device, raid_device); 724 if (!ask_me_yes_or_no(tmp)) { 725 return; 726 } 727 for (pos = currline; pos < disklist->entries - 1; pos++) { 728 /* memcpy((void*)&disklist->el[pos], (void*)&disklist->el[pos+1], sizeof(struct s_disk)); */ 729 strcpy(disklist->el[pos].device, disklist->el[pos + 1].device); 730 } 731 disklist->entries--; 764 732 } 765 733 … … 776 744 */ 777 745 void 778 delete_mountlist_entry (struct mountlist_itself *mountlist, 779 struct raidlist_itself *raidlist, 780 newtComponent listbox, int currline, void *keylist[]) 746 delete_mountlist_entry(struct mountlist_itself *mountlist, 747 struct raidlist_itself *raidlist, 748 newtComponent listbox, int currline, 749 void *keylist[]) 781 750 { 782 751 783 752 /** int ***************************************************************/ 784 753 int pos = 0; 785 754 786 755 /** buffers ***********************************************************/ 787 756 char tmp[MAX_STR_LEN]; 788 757 char device[MAX_STR_LEN]; 789 758 790 759 791 assert(mountlist!=NULL); 792 assert(raidlist!=NULL); 793 assert(listbox!=NULL); 794 assert(keylist!=NULL); 795 796 pos = 797 which_raid_device_is_using_this_partition (raidlist, 798 mountlist->el[currline]. 799 device); 800 if (pos >= 0) 801 { 802 sprintf (tmp, "Cannot delete %s: it is in use by RAID device %s", 803 mountlist->el[currline].device, raidlist->el[pos].OSSWAP (raid_device, volname)); 804 popup_and_OK (tmp); 805 return; 806 } 807 sprintf (tmp, "Delete %s - are you sure?", mountlist->el[currline].device); 808 if (!ask_me_yes_or_no (tmp)) 809 { 810 return; 811 } 812 if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB)) 813 { 814 strcpy (device, mountlist->el[currline].device); 815 delete_raidlist_entry (mountlist, raidlist, device); 816 for (currline = 0; 817 currline < mountlist->entries 818 && strcmp (mountlist->el[currline].device, device); currline++); 819 if (currline == mountlist->entries) 820 { 821 log_it ("Dev is gone. I can't delete it. Ho-hum"); 822 return; 823 } 824 } 825 memcpy ((void *) &mountlist->el[currline], 826 (void *) &mountlist->el[mountlist->entries - 1], 827 sizeof (struct mountlist_line)); 828 mountlist->entries--; 829 redraw_mountlist (mountlist, keylist, listbox); 760 assert(mountlist != NULL); 761 assert(raidlist != NULL); 762 assert(listbox != NULL); 763 assert(keylist != NULL); 764 765 pos = 766 which_raid_device_is_using_this_partition(raidlist, 767 mountlist->el[currline]. 768 device); 769 if (pos >= 0) { 770 sprintf(tmp, "Cannot delete %s: it is in use by RAID device %s", 771 mountlist->el[currline].device, 772 raidlist->el[pos].OSSWAP(raid_device, volname)); 773 popup_and_OK(tmp); 774 return; 775 } 776 sprintf(tmp, "Delete %s - are you sure?", 777 mountlist->el[currline].device); 778 if (!ask_me_yes_or_no(tmp)) { 779 return; 780 } 781 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) { 782 strcpy(device, mountlist->el[currline].device); 783 delete_raidlist_entry(mountlist, raidlist, device); 784 for (currline = 0; 785 currline < mountlist->entries 786 && strcmp(mountlist->el[currline].device, device); 787 currline++); 788 if (currline == mountlist->entries) { 789 log_it("Dev is gone. I can't delete it. Ho-hum"); 790 return; 791 } 792 } 793 memcpy((void *) &mountlist->el[currline], 794 (void *) &mountlist->el[mountlist->entries - 1], 795 sizeof(struct mountlist_line)); 796 mountlist->entries--; 797 redraw_mountlist(mountlist, keylist, listbox); 830 798 } 831 799 … … 839 807 */ 840 808 void 841 delete_raidlist_entry 842 843 { 844 809 delete_raidlist_entry(struct mountlist_itself *mountlist, 810 struct raidlist_itself *raidlist, char *device) 811 { 812 845 813 /** int ***************************************************************/ 846 847 int items = 0;814 int i = 0; 815 int items = 0; 848 816 849 817 /** bool **************************************************************/ 850 818 bool delete_partitions_too; 851 819 852 820 /** buffers ***********************************************************/ 853 char tmp[MAX_STR_LEN]; 854 855 assert(mountlist!=NULL); 856 assert(raidlist!=NULL); 857 assert_string_is_neither_NULL_nor_zerolength(device); 858 859 i = find_raid_device_in_raidlist (raidlist, device); 860 if (i < 0) 861 { 862 return; 863 } 864 sprintf (tmp, "Do you want me to delete %s's partitions, too?", device); 865 delete_partitions_too = ask_me_yes_or_no (tmp); 866 if (delete_partitions_too) 867 { 821 char tmp[MAX_STR_LEN]; 822 823 assert(mountlist != NULL); 824 assert(raidlist != NULL); 825 assert_string_is_neither_NULL_nor_zerolength(device); 826 827 i = find_raid_device_in_raidlist(raidlist, device); 828 if (i < 0) { 829 return; 830 } 831 sprintf(tmp, "Do you want me to delete %s's partitions, too?", device); 832 delete_partitions_too = ask_me_yes_or_no(tmp); 833 if (delete_partitions_too) { 868 834 #ifdef __FreeBSD__ 869 // static so it's zeroed 870 static struct list_of_disks d; 871 int x, y, z; 872 873 for (x = 0; x < raidlist->el[i].plexes; ++x) { 874 for (y = 0; y < raidlist->el[i].plex[x].subdisks; ++y) { 875 for (z = 0; z < raidlist->disks.entries; ++z) { 876 if (!strcmp (raidlist->el[i].plex[x].sd[y].which_device, 877 raidlist->disks.el[z].name)) { 878 strcpy (d.el [d.entries ].name, raidlist->disks.el[z].name); 879 strcpy (d.el [d.entries++].device, raidlist->disks.el[z].device); 880 } 881 } 882 } 883 } 884 885 del_partns_listed_in_disklist (mountlist, raidlist, &d); 835 // static so it's zeroed 836 static struct list_of_disks d; 837 int x, y, z; 838 839 for (x = 0; x < raidlist->el[i].plexes; ++x) { 840 for (y = 0; y < raidlist->el[i].plex[x].subdisks; ++y) { 841 for (z = 0; z < raidlist->disks.entries; ++z) { 842 if (!strcmp(raidlist->el[i].plex[x].sd[y].which_device, 843 raidlist->disks.el[z].name)) { 844 strcpy(d.el[d.entries].name, 845 raidlist->disks.el[z].name); 846 strcpy(d.el[d.entries++].device, 847 raidlist->disks.el[z].device); 848 } 849 } 850 } 851 } 852 853 del_partns_listed_in_disklist(mountlist, raidlist, &d); 886 854 #else 887 del_partns_listed_in_disklist(mountlist, raidlist,888 889 del_partns_listed_in_disklist(mountlist, raidlist,890 891 del_partns_listed_in_disklist(mountlist, raidlist,892 893 del_partns_listed_in_disklist(mountlist, raidlist,894 855 del_partns_listed_in_disklist(mountlist, raidlist, 856 &raidlist->el[i].data_disks); 857 del_partns_listed_in_disklist(mountlist, raidlist, 858 &raidlist->el[i].spare_disks); 859 del_partns_listed_in_disklist(mountlist, raidlist, 860 &raidlist->el[i].parity_disks); 861 del_partns_listed_in_disklist(mountlist, raidlist, 862 &raidlist->el[i].failed_disks); 895 863 #endif 896 } 897 items = raidlist->entries; 898 if (items == 1) 899 { 900 items = 0; 901 } 902 else 903 { 904 log_it (tmp); 905 memcpy ((void *) &raidlist->el[i], (void *) &raidlist->el[items - 1], 906 sizeof (struct OSSWAP(raid_device_record, vinum_volume))); 907 items--; 908 } 909 raidlist->entries = items; 864 } 865 items = raidlist->entries; 866 if (items == 1) { 867 items = 0; 868 } else { 869 log_it(tmp); 870 memcpy((void *) &raidlist->el[i], 871 (void *) &raidlist->el[items - 1], 872 sizeof(struct OSSWAP (raid_device_record, vinum_volume))); 873 items--; 874 } 875 raidlist->entries = items; 910 876 } 911 877 … … 918 884 * @ingroup restoreGuiVarslist 919 885 */ 920 void 921 delete_varslist_entry (struct raid_device_record *raidrec, int lino) 886 void delete_varslist_entry(struct raid_device_record *raidrec, int lino) 922 887 { 923 888 924 889 /** buffers ************************************************************/ 925 890 char tmp[MAX_STR_LEN]; 926 891 927 892 /** structures *********************************************************/ 928 struct additional_raid_variables *av; 929 930 assert(raidrec!=NULL); 931 932 av = &raidrec->additional_vars; 933 sprintf (tmp, "Delete %s - are you sure?", av->el[lino].label); 934 if (ask_me_yes_or_no (tmp)) 935 { 936 if (!strcmp (av->el[lino].label, "persistent-superblock") 937 || !strcmp (av->el[lino].label, "chunk-size")) 938 { 939 sprintf (tmp, "%s must not be deleted. It would be bad.", 940 av->el[lino].label); 941 popup_and_OK (tmp); 942 } 943 else 944 { 945 memcpy ((void *) &av->el[lino], (void *) &av->el[av->entries--], 946 sizeof (struct raid_var_line)); 947 } 948 } 893 struct additional_raid_variables *av; 894 895 assert(raidrec != NULL); 896 897 av = &raidrec->additional_vars; 898 sprintf(tmp, "Delete %s - are you sure?", av->el[lino].label); 899 if (ask_me_yes_or_no(tmp)) { 900 if (!strcmp(av->el[lino].label, "persistent-superblock") 901 || !strcmp(av->el[lino].label, "chunk-size")) { 902 sprintf(tmp, "%s must not be deleted. It would be bad.", 903 av->el[lino].label); 904 popup_and_OK(tmp); 905 } else { 906 memcpy((void *) &av->el[lino], (void *) &av->el[av->entries--], 907 sizeof(struct raid_var_line)); 908 } 909 } 949 910 } 950 911 #endif … … 960 921 */ 961 922 int 962 redraw_filelist 963 923 redraw_filelist(struct s_node *filelist, void *keylist[ARBITRARY_MAXIMUM], 924 newtComponent listbox) 964 925 { 965 926 966 927 /** int ***************************************************************/ 967 968 969 928 static int lines_in_flist_window = 0; 929 static int depth = 0; 930 int i = 0; 970 931 971 932 /** structures *******************************************************/ 972 933 struct s_node *node; 973 934 974 935 /** buffers **********************************************************/ 975 976 936 static char current_filename[MAX_STR_LEN]; 937 char tmp[MAX_STR_LEN + 2]; 977 938 978 939 /** bool *************************************************************/ 979 940 /* void*dummyptr; */ 980 bool dummybool; 981 static bool warned_already; 982 983 assert(filelist!=NULL); 984 assert(keylist!=NULL); 985 assert(listbox!=NULL); 986 987 988 if (depth == 0) 989 { 990 lines_in_flist_window = 0; 991 warned_already = FALSE; 992 for (i = 0; i < ARBITRARY_MAXIMUM; i++) 993 { 994 g_strings_of_flist_window[i][0] = '\0'; 995 g_is_path_selected[i] = FALSE; 996 } 997 } 998 for (node = filelist; node != NULL; node = node->right) 999 { 1000 current_filename[depth] = node->ch; 1001 if (node->down) 1002 { 1003 depth++; 1004 i = redraw_filelist (node->down, keylist, listbox); 1005 depth--; 1006 } 1007 if (node->ch == '\0' && node->expanded) 1008 { 1009 if (lines_in_flist_window == ARBITRARY_MAXIMUM) 1010 { 1011 if (!warned_already) 1012 { 1013 warned_already = TRUE; 1014 sprintf (tmp, 1015 "Too many lines. Displaying first %d entries only. Close a directory to see more.", 1016 ARBITRARY_MAXIMUM); 1017 popup_and_OK (tmp); 1018 } 1019 } 1020 else 1021 { 1022 strcpy (g_strings_of_flist_window[lines_in_flist_window], 1023 current_filename); 1024 g_is_path_selected[lines_in_flist_window] = node->selected; 1025 lines_in_flist_window++; 1026 } 1027 } 1028 } 1029 if (depth == 0) 1030 { 1031 if (lines_in_flist_window > ARBITRARY_MAXIMUM) 1032 { 1033 lines_in_flist_window = ARBITRARY_MAXIMUM; 1034 } 941 bool dummybool; 942 static bool warned_already; 943 944 assert(filelist != NULL); 945 assert(keylist != NULL); 946 assert(listbox != NULL); 947 948 949 if (depth == 0) { 950 lines_in_flist_window = 0; 951 warned_already = FALSE; 952 for (i = 0; i < ARBITRARY_MAXIMUM; i++) { 953 g_strings_of_flist_window[i][0] = '\0'; 954 g_is_path_selected[i] = FALSE; 955 } 956 } 957 for (node = filelist; node != NULL; node = node->right) { 958 current_filename[depth] = node->ch; 959 if (node->down) { 960 depth++; 961 i = redraw_filelist(node->down, keylist, listbox); 962 depth--; 963 } 964 if (node->ch == '\0' && node->expanded) { 965 if (lines_in_flist_window == ARBITRARY_MAXIMUM) { 966 if (!warned_already) { 967 warned_already = TRUE; 968 sprintf(tmp, 969 "Too many lines. Displaying first %d entries only. Close a directory to see more.", 970 ARBITRARY_MAXIMUM); 971 popup_and_OK(tmp); 972 } 973 } else { 974 strcpy(g_strings_of_flist_window[lines_in_flist_window], 975 current_filename); 976 g_is_path_selected[lines_in_flist_window] = node->selected; 977 lines_in_flist_window++; 978 } 979 } 980 } 981 if (depth == 0) { 982 if (lines_in_flist_window > ARBITRARY_MAXIMUM) { 983 lines_in_flist_window = ARBITRARY_MAXIMUM; 984 } 1035 985 /* do an elementary sort */ 1036 for (i = 1; i < lines_in_flist_window; i++) 1037 { 1038 if (strcmp 1039 (g_strings_of_flist_window[i], 1040 g_strings_of_flist_window[i - 1]) < 0) 1041 { 1042 strcpy (tmp, g_strings_of_flist_window[i]); 1043 strcpy (g_strings_of_flist_window[i], 1044 g_strings_of_flist_window[i - 1]); 1045 strcpy (g_strings_of_flist_window[i - 1], tmp); 1046 dummybool = g_is_path_selected[i]; 1047 g_is_path_selected[i] = g_is_path_selected[i - 1]; 1048 g_is_path_selected[i - 1] = dummybool; 1049 i = 0; 1050 } 1051 } 986 for (i = 1; i < lines_in_flist_window; i++) { 987 if (strcmp 988 (g_strings_of_flist_window[i], 989 g_strings_of_flist_window[i - 1]) < 0) { 990 strcpy(tmp, g_strings_of_flist_window[i]); 991 strcpy(g_strings_of_flist_window[i], 992 g_strings_of_flist_window[i - 1]); 993 strcpy(g_strings_of_flist_window[i - 1], tmp); 994 dummybool = g_is_path_selected[i]; 995 g_is_path_selected[i] = g_is_path_selected[i - 1]; 996 g_is_path_selected[i - 1] = dummybool; 997 i = 0; 998 } 999 } 1052 1000 /* write list to screen */ 1053 newtListboxClear (listbox); 1054 for (i = 0; i < lines_in_flist_window; i++) 1055 { 1056 sprintf (tmp, "%c%c %-80s", (g_is_path_selected[i] ? '*' : ' '), 1057 (g_is_path_expanded[i] ? '+' : '-'), 1058 strip_path(g_strings_of_flist_window[i])); 1059 tmp[70] = '\0'; 1060 keylist[i] = (void *) i; 1061 newtListboxAppendEntry (listbox, tmp, keylist[i]); 1062 } 1063 return (lines_in_flist_window); 1064 } 1065 else 1066 { 1067 return (0); 1068 } 1001 newtListboxClear(listbox); 1002 for (i = 0; i < lines_in_flist_window; i++) { 1003 sprintf(tmp, "%c%c %-80s", (g_is_path_selected[i] ? '*' : ' '), 1004 (g_is_path_expanded[i] ? '+' : '-'), 1005 strip_path(g_strings_of_flist_window[i])); 1006 tmp[70] = '\0'; 1007 keylist[i] = (void *) i; 1008 newtListboxAppendEntry(listbox, tmp, keylist[i]); 1009 } 1010 return (lines_in_flist_window); 1011 } else { 1012 return (0); 1013 } 1069 1014 } 1070 1015 … … 1077 1022 * @ingroup restoreUtilityGroup 1078 1023 */ 1079 char *strip_path(char *tmp) 1024 char *strip_path(char *tmp) 1080 1025 { 1081 1026 … … 1083 1028 int slashloc = 0, lastslashloc = 0; 1084 1029 1085 while(tmp[i] != '\0') 1086 { /* Count the slashes in tmp 1087 1 slash per dir */ 1088 if( tmp[i] == '/') 1089 { 1090 slashcount++; 1091 lastslashloc = slashloc; 1092 slashloc = i; 1093 if(tmp[i + 1] == '\0') 1094 { /* if this slash is last char, back off */ 1095 slashcount--; 1096 slashloc = lastslashloc; 1097 } 1098 } 1099 i++; 1100 } 1101 if(slashcount > 0) slashcount--; /* Keep one slash 'cos Hugh does... */ 1102 1103 for(i=0; i<slashcount; i++) 1104 { /* Replace each dir with a space char */ 1105 tmpnopath[i] = ' '; 1030 while (tmp[i] != '\0') { /* Count the slashes in tmp 1031 1 slash per dir */ 1032 if (tmp[i] == '/') { 1033 slashcount++; 1034 lastslashloc = slashloc; 1035 slashloc = i; 1036 if (tmp[i + 1] == '\0') { /* if this slash is last char, back off */ 1037 slashcount--; 1038 slashloc = lastslashloc; 1039 } 1040 } 1041 i++; 1042 } 1043 if (slashcount > 0) 1044 slashcount--; /* Keep one slash 'cos Hugh does... */ 1045 1046 for (i = 0; i < slashcount; i++) { /* Replace each dir with a space char */ 1047 tmpnopath[i] = ' '; 1106 1048 } 1107 1049 1108 1050 i = slashloc; 1109 1051 j = slashcount; 1110 while(tmp[i] != '\0') 1111 { /* Now add what's left of tmp */ 1112 if( (tmpprevpath[j] == ' ' || tmpprevpath[j] == '^') 1113 && tmp[i] == '/' 1114 && tmpnopath[j - 1] != '^' 1115 && j != 0) 1116 { /* Add a pointer upwards if this is not in the same dir as line above */ 1117 tmpnopath[j - 1] = '^'; 1118 } else { 1119 tmpnopath[j++] = tmp[i++]; 1120 } 1052 while (tmp[i] != '\0') { /* Now add what's left of tmp */ 1053 if ((tmpprevpath[j] == ' ' || tmpprevpath[j] == '^') 1054 && tmp[i] == '/' && tmpnopath[j - 1] != '^' && j != 0) { /* Add a pointer upwards if this is not in the same dir as line above */ 1055 tmpnopath[j - 1] = '^'; 1056 } else { 1057 tmpnopath[j++] = tmp[i++]; 1058 } 1121 1059 } 1122 1060 tmpnopath[j] = '\0'; 1123 1061 1124 strcpy(tmpprevpath, tmpnopath); 1125 1126 return (tmpnopath);1062 strcpy(tmpprevpath, tmpnopath); /* Make a copy for next iteration */ 1063 1064 return (tmpnopath); 1127 1065 } 1128 1066 … … 1133 1071 * @return 0 if the user pressed OK, 1 if they pressed Cancel. 1134 1072 */ 1135 int 1136 edit_filelist (struct s_node *filelist) 1073 int edit_filelist(struct s_node *filelist) 1137 1074 { 1138 1075 1139 1076 /** newt **************************************************************/ 1140 1141 newtComponent bLess =NULL;1142 newtComponent bMore =NULL;1143 newtComponent bToggle =NULL;1144 newtComponent bOK =NULL;1145 newtComponent bCancel =NULL;1146 newtComponent b_res =NULL;1147 newtComponent filelistListbox =NULL;1148 newtComponent bRegex =NULL;1077 newtComponent myForm; 1078 newtComponent bLess = NULL; 1079 newtComponent bMore = NULL; 1080 newtComponent bToggle = NULL; 1081 newtComponent bOK = NULL; 1082 newtComponent bCancel = NULL; 1083 newtComponent b_res = NULL; 1084 newtComponent filelistListbox = NULL; 1085 newtComponent bRegex = NULL; 1149 1086 1150 1087 /** int ***************************************************************/ … … 1155 1092 1156 1093 /** ???? **************************************************************/ 1157 1158 1094 void *curr_choice; 1095 void *keylist[ARBITRARY_MAXIMUM]; 1159 1096 1160 1097 /** buffers ***********************************************************/ 1161 1098 char tmp[MAX_STR_LEN]; 1162 1099 1163 1100 /** bool **************************************************************/ 1164 1101 bool dummybool; 1165 1102 1166 1103 /* struct s_node *node; */ 1167 1104 1168 assert(filelist!=NULL); 1169 1170 log_to_screen ("Editing filelist"); 1171 newtPushHelpLine 1172 (" Please edit the filelist to your satisfaction, then click OK or Cancel."); 1173 j = 4; 1174 bLess = newtCompactButton (j, 17, " Less "); 1175 bMore = newtCompactButton (j += 12, 17, " More "); 1176 bToggle = newtCompactButton (j += 12, 17, "Toggle"); 1177 bRegex = newtCompactButton (j += 12, 17, "RegEx"); 1178 bCancel = newtCompactButton (j += 12, 17, "Cancel"); 1179 bOK = newtCompactButton (j += 12, 17, " OK "); 1180 filelistListbox = 1181 newtListbox (2, 1, 15, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1182 toggle_all_root_dirs_on (filelist); 1183 lines_in_flist_window = 1184 redraw_filelist (filelist, keylist, filelistListbox); 1185 newtOpenWindow (1, 3, 77, 18, "Editing filelist"); 1186 myForm = newtForm (NULL, NULL, 0); 1187 newtFormAddComponents (myForm, filelistListbox, bLess, bMore, bToggle, 1188 bRegex, bCancel, bOK, NULL); 1189 while (!finished) 1190 { 1191 b_res = newtRunForm (myForm); 1192 if (b_res == bOK) 1193 { 1194 finished = 1195 ask_me_yes_or_no ("Are you happy with your file selection?"); 1196 } 1197 else if (b_res == bCancel) 1198 { 1199 finished = TRUE; 1200 } 1201 else if (b_res == bRegex) 1202 { 1203 popup_and_OK ("I haven't implemented this yet..."); 1204 } 1205 else 1206 { 1207 curr_choice = newtListboxGetCurrent (filelistListbox); 1208 for (indexno = 0; 1209 indexno < lines_in_flist_window 1210 && keylist[indexno] != curr_choice; indexno++); 1211 if (indexno == lines_in_flist_window) 1212 { 1213 log_it 1214 ("I don't know what this button does; assuming I am to toggle 1st entry"); 1215 indexno = 0; 1216 } 1217 sprintf (tmp, "You selected '%s'", 1218 g_strings_of_flist_window[indexno]); 1219 log_it (tmp); 1220 if (b_res == bMore) 1221 { 1222 g_is_path_expanded[indexno] = TRUE; 1223 toggle_path_expandability (filelist, 1224 g_strings_of_flist_window[indexno], 1225 TRUE); 1226 lines_in_flist_window = 1227 redraw_filelist (filelist, keylist, filelistListbox); 1228 newtListboxSetCurrentByKey (filelistListbox, curr_choice); 1229 } 1230 else if (b_res == bLess) 1231 { 1232 g_is_path_expanded[indexno] = FALSE; 1233 toggle_path_expandability (filelist, 1234 g_strings_of_flist_window[indexno], 1235 FALSE); 1236 lines_in_flist_window = 1237 redraw_filelist (filelist, keylist, filelistListbox); 1238 newtListboxSetCurrentByKey (filelistListbox, curr_choice); 1239 } 1240 else 1241 { 1242 if (!strcmp (g_strings_of_flist_window[indexno], "/")) 1243 { 1244 dummybool = !g_is_path_selected[indexno]; 1245 for (j = 1; j < lines_in_flist_window; j++) 1246 { 1247 toggle_path_selection (filelist, 1248 g_strings_of_flist_window[j], 1249 dummybool); 1250 } 1251 } 1252 else 1253 { 1254 toggle_path_selection (filelist, 1255 g_strings_of_flist_window[indexno], 1256 !g_is_path_selected[indexno]); 1257 lines_in_flist_window = 1258 redraw_filelist (filelist, keylist, filelistListbox); 1259 } 1260 newtListboxSetCurrentByKey (filelistListbox, curr_choice); 1261 } 1262 for (indexno = 0; 1263 indexno < lines_in_flist_window 1264 && keylist[indexno] != curr_choice; indexno++); 1265 if (indexno == lines_in_flist_window) 1266 { 1267 log_it 1268 ("Layout of table has changed. Y pointer is reverting to zero."); 1269 indexno = 0; 1270 } 1271 } 1272 } 1273 newtFormDestroy (myForm); 1274 newtPopWindow (); 1275 newtPopHelpLine (); 1276 if (b_res == bOK) 1277 { 1278 return (0); 1279 } 1280 else 1281 { 1105 assert(filelist != NULL); 1106 1107 log_to_screen("Editing filelist"); 1108 newtPushHelpLine 1109 (" Please edit the filelist to your satisfaction, then click OK or Cancel."); 1110 j = 4; 1111 bLess = newtCompactButton(j, 17, " Less "); 1112 bMore = newtCompactButton(j += 12, 17, " More "); 1113 bToggle = newtCompactButton(j += 12, 17, "Toggle"); 1114 bRegex = newtCompactButton(j += 12, 17, "RegEx"); 1115 bCancel = newtCompactButton(j += 12, 17, "Cancel"); 1116 bOK = newtCompactButton(j += 12, 17, " OK "); 1117 filelistListbox = 1118 newtListbox(2, 1, 15, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1119 toggle_all_root_dirs_on(filelist); 1120 lines_in_flist_window = 1121 redraw_filelist(filelist, keylist, filelistListbox); 1122 newtOpenWindow(1, 3, 77, 18, "Editing filelist"); 1123 myForm = newtForm(NULL, NULL, 0); 1124 newtFormAddComponents(myForm, filelistListbox, bLess, bMore, bToggle, 1125 bRegex, bCancel, bOK, NULL); 1126 while (!finished) { 1127 b_res = newtRunForm(myForm); 1128 if (b_res == bOK) { 1129 finished = 1130 ask_me_yes_or_no 1131 ("Are you happy with your file selection?"); 1132 } else if (b_res == bCancel) { 1133 finished = TRUE; 1134 } else if (b_res == bRegex) { 1135 popup_and_OK("I haven't implemented this yet..."); 1136 } else { 1137 curr_choice = newtListboxGetCurrent(filelistListbox); 1138 for (indexno = 0; 1139 indexno < lines_in_flist_window 1140 && keylist[indexno] != curr_choice; indexno++); 1141 if (indexno == lines_in_flist_window) { 1142 log_it 1143 ("I don't know what this button does; assuming I am to toggle 1st entry"); 1144 indexno = 0; 1145 } 1146 sprintf(tmp, "You selected '%s'", 1147 g_strings_of_flist_window[indexno]); 1148 log_it(tmp); 1149 if (b_res == bMore) { 1150 g_is_path_expanded[indexno] = TRUE; 1151 toggle_path_expandability(filelist, 1152 g_strings_of_flist_window 1153 [indexno], TRUE); 1154 lines_in_flist_window = 1155 redraw_filelist(filelist, keylist, filelistListbox); 1156 newtListboxSetCurrentByKey(filelistListbox, curr_choice); 1157 } else if (b_res == bLess) { 1158 g_is_path_expanded[indexno] = FALSE; 1159 toggle_path_expandability(filelist, 1160 g_strings_of_flist_window 1161 [indexno], FALSE); 1162 lines_in_flist_window = 1163 redraw_filelist(filelist, keylist, filelistListbox); 1164 newtListboxSetCurrentByKey(filelistListbox, curr_choice); 1165 } else { 1166 if (!strcmp(g_strings_of_flist_window[indexno], "/")) { 1167 dummybool = !g_is_path_selected[indexno]; 1168 for (j = 1; j < lines_in_flist_window; j++) { 1169 toggle_path_selection(filelist, 1170 g_strings_of_flist_window[j], 1171 dummybool); 1172 } 1173 } else { 1174 toggle_path_selection(filelist, 1175 g_strings_of_flist_window 1176 [indexno], 1177 !g_is_path_selected[indexno]); 1178 lines_in_flist_window = 1179 redraw_filelist(filelist, keylist, 1180 filelistListbox); 1181 } 1182 newtListboxSetCurrentByKey(filelistListbox, curr_choice); 1183 } 1184 for (indexno = 0; 1185 indexno < lines_in_flist_window 1186 && keylist[indexno] != curr_choice; indexno++); 1187 if (indexno == lines_in_flist_window) { 1188 log_it 1189 ("Layout of table has changed. Y pointer is reverting to zero."); 1190 indexno = 0; 1191 } 1192 } 1193 } 1194 newtFormDestroy(myForm); 1195 newtPopWindow(); 1196 newtPopHelpLine(); 1197 if (b_res == bOK) { 1198 return (0); 1199 } else { 1282 1200 /* popup_and_OK("You pushed 'cancel'. I shall now abort."); */ 1283 1284 1201 return (1); 1202 } 1285 1203 } 1286 1204 … … 1296 1214 */ 1297 1215 void 1298 edit_mountlist_entry 1299 struct raidlist_itself *raidlist, newtComponent listbox,1300 1216 edit_mountlist_entry(struct mountlist_itself *mountlist, 1217 struct raidlist_itself *raidlist, 1218 newtComponent listbox, int currline, void *keylist[]) 1301 1219 { 1302 1220 1303 1221 /** structures ********************************************************/ 1304 1222 static struct raidlist_itself bkp_raidlist; 1305 1223 1306 1224 /** newt **************************************************************/ 1307 1225 newtComponent myForm; 1308 1226 newtComponent bOK; 1309 1227 newtComponent bCancel; … … 1324 1242 char size_str[MAX_STR_LEN]; 1325 1243 char format_str[MAX_STR_LEN]; 1326 1327 1244 char tmp[MAX_STR_LEN]; 1245 char device_used_to_be[MAX_STR_LEN]; 1328 1246 char mountpt_used_to_be[MAX_STR_LEN]; 1329 1247 … … 1335 1253 1336 1254 /** int ***************************************************************/ 1337 int j = 0; 1338 1339 assert(mountlist!=NULL); 1340 assert(raidlist!=NULL); 1341 assert(listbox!=NULL); 1342 assert(keylist!=NULL); 1343 1344 memcpy ((void *) &bkp_raidlist, (void *) raidlist, 1345 sizeof (struct raidlist_itself)); 1346 strcpy (device_str, mountlist->el[currline].device); 1347 strcpy (device_used_to_be, mountlist->el[currline].device); 1348 strcpy (mountpoint_str, mountlist->el[currline].mountpoint); 1349 strcpy (mountpt_used_to_be, mountlist->el[currline].mountpoint); 1350 strcpy (format_str, mountlist->el[currline].format); 1351 sprintf (size_str, "%lld", mountlist->el[currline].size / 1024); 1352 newtOpenWindow (20, 5, 48, 10, "Edit entry"); 1353 label0 = newtLabel (2, 1, "Device:"); 1354 label1 = newtLabel (2, 2, "Mountpoint:"); 1355 label2 = newtLabel (2, 3, "Size (MB): "); 1356 label3 = newtLabel (2, 4, "Format: "); 1357 deviceComp = newtEntry (14, 1, device_str, 30, (void*)&device_here, 0); 1358 mountpointComp = newtEntry (14, 2, mountpoint_str, 30, (void*)&mountpoint_here, 0); 1359 formatComp = newtEntry (14, 4, format_str, 15, (void*)&format_here, 0); 1360 if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB) 1361 || !strcmp (mountlist->el[currline].mountpoint, "image")) 1362 { 1363 sizeComp = newtLabel (14, 3, size_str); 1364 } 1365 else 1366 { 1367 sizeComp = newtEntry (14, 3, size_str, 10, (void*)&size_here, 0); 1368 } 1369 bOK = newtButton (2, 6, " OK "); 1370 bCancel = newtButton (14, 6, "Cancel"); 1371 if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB)) 1372 { 1373 b_raid = newtButton (26, 6, "RAID.."); 1374 } 1375 newtPushHelpLine 1376 (" Edit this partition's mountpoint, size and format; then click 'OK'."); 1377 myForm = newtForm (NULL, NULL, 0); 1378 newtFormAddComponents (myForm, deviceComp, mountpointComp, sizeComp, 1379 formatComp, label0, label1, label2, label3, bOK, 1380 bCancel, b_raid, NULL); 1381 for (b_res = NULL; b_res != bOK && b_res != bCancel;) 1382 { 1383 b_res = newtRunForm (myForm); 1384 strcpy (device_str, device_here); 1385 strip_spaces (device_str); 1386 strcpy (mountpoint_str, mountpoint_here); 1387 strip_spaces (mountpoint_str); 1388 strcpy (format_str, format_here); 1389 strip_spaces (format_str); 1390 if (b_res == bOK && strstr (device_str, RAID_DEVICE_STUB) 1391 && strstr (device_used_to_be, RAID_DEVICE_STUB) 1392 && strcmp (device_str, device_used_to_be)) 1393 { 1394 popup_and_OK ("You can't change /dev/mdX to /dev/mdY."); 1395 b_res = NULL; 1396 continue; 1397 } 1398 else if (b_res == bOK && !strcmp (mountpoint_str, "image") 1399 && strcmp (mountpt_used_to_be, "image")) 1400 { 1401 popup_and_OK ("You can't change a regular device to an image."); 1402 b_res = NULL; 1403 continue; 1404 } 1405 if (!strstr (mountlist->el[currline].device, RAID_DEVICE_STUB) 1406 && strcmp (mountlist->el[currline].mountpoint, "image")) 1407 { 1408 strcpy (size_str, size_here); 1409 strip_spaces (size_str); 1410 } 1411 else 1412 { 1413 sprintf (size_str, "%ld", 1414 calculate_raid_device_size (mountlist, raidlist, 1415 mountlist->el[currline]. 1416 device) / 1024); 1417 newtLabelSetText (sizeComp, size_str); 1418 } 1419 /* do not let user click RAID button if user has changed device_str */ 1420 if (b_res == b_raid) 1421 { 1422 if (strcmp (device_str, mountlist->el[currline].device)) 1423 { 1424 /* 1425 can't change mountlist's entry from /dex/mdX to /dev/mdY: it would ugly 1426 when you try to map the changes over to the raidtab list, trust me 1427 */ 1428 popup_and_OK 1429 ("You cannot edit the RAID settings until you have OK'd your change to the device node."); 1430 } 1431 else 1432 { 1433 j = 1434 find_raid_device_in_raidlist (raidlist, 1435 mountlist->el[currline].device); 1436 if (j < 0) 1437 { 1438 sprintf (tmp, 1439 "/etc/raidtab does not have an entry for %s; please delete it and add it again", 1440 mountlist->el[currline].device); 1441 popup_and_OK (tmp); 1442 } 1443 else 1444 { 1445 log_it ("edit_raidlist_entry - calling"); 1446 edit_raidlist_entry (mountlist, raidlist, &raidlist->el[j], 1447 currline); 1448 } 1449 } 1450 } 1451 } 1452 newtFormDestroy (myForm); 1453 newtPopHelpLine (); 1454 newtPopWindow (); 1455 if (b_res == bCancel) 1456 { 1457 memcpy ((void *) raidlist, (void *) &bkp_raidlist, 1458 sizeof (struct raidlist_itself)); 1459 return; 1460 } 1461 strcpy (mountlist->el[currline].device, device_str); 1462 strcpy (mountlist->el[currline].mountpoint, mountpoint_str); 1463 strcpy (mountlist->el[currline].format, format_str); 1464 if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB) 1465 || !strcmp (mountlist->el[currline].mountpoint, "image")) 1466 { 1467 mountlist->el[currline].size = 1468 calculate_raid_device_size (mountlist, raidlist, 1469 mountlist->el[currline].device); 1470 } 1471 else 1472 { 1473 mountlist->el[currline].size = atol (size_str) * 1024; 1474 } 1475 newtListboxSetEntry (listbox, (int) keylist[currline], 1476 mountlist_entry_to_string (mountlist, currline)); 1477 /* if new /dev/md RAID device then do funky stuff */ 1478 if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB) 1479 && !strstr (device_used_to_be, RAID_DEVICE_STUB)) 1480 { 1481 initiate_new_raidlist_entry (raidlist, mountlist, currline, device_str); 1482 } 1483 /* if moving from RAID to non-RAID then do funky stuff */ 1484 else if (strstr (device_used_to_be, RAID_DEVICE_STUB) 1485 && !strstr (device_str, RAID_DEVICE_STUB)) 1486 { 1487 delete_raidlist_entry (mountlist, raidlist, device_str); 1488 } 1489 /* if moving a non-RAID to another non-RAID then re-jig any RAID disks, if necessary */ 1490 else if (!strstr (device_used_to_be, RAID_DEVICE_STUB) 1491 && !strstr (device_str, RAID_DEVICE_STUB)) 1492 { 1493 rejig_partition_name_in_raidlist_if_necessary (raidlist, 1494 device_used_to_be, 1495 device_str); 1496 } 1255 int j = 0; 1256 1257 assert(mountlist != NULL); 1258 assert(raidlist != NULL); 1259 assert(listbox != NULL); 1260 assert(keylist != NULL); 1261 1262 memcpy((void *) &bkp_raidlist, (void *) raidlist, 1263 sizeof(struct raidlist_itself)); 1264 strcpy(device_str, mountlist->el[currline].device); 1265 strcpy(device_used_to_be, mountlist->el[currline].device); 1266 strcpy(mountpoint_str, mountlist->el[currline].mountpoint); 1267 strcpy(mountpt_used_to_be, mountlist->el[currline].mountpoint); 1268 strcpy(format_str, mountlist->el[currline].format); 1269 sprintf(size_str, "%lld", mountlist->el[currline].size / 1024); 1270 newtOpenWindow(20, 5, 48, 10, "Edit entry"); 1271 label0 = newtLabel(2, 1, "Device:"); 1272 label1 = newtLabel(2, 2, "Mountpoint:"); 1273 label2 = newtLabel(2, 3, "Size (MB): "); 1274 label3 = newtLabel(2, 4, "Format: "); 1275 deviceComp = 1276 newtEntry(14, 1, device_str, 30, (void *) &device_here, 0); 1277 mountpointComp = 1278 newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0); 1279 formatComp = 1280 newtEntry(14, 4, format_str, 15, (void *) &format_here, 0); 1281 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1282 || !strcmp(mountlist->el[currline].mountpoint, "image")) { 1283 sizeComp = newtLabel(14, 3, size_str); 1284 } else { 1285 sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0); 1286 } 1287 bOK = newtButton(2, 6, " OK "); 1288 bCancel = newtButton(14, 6, "Cancel"); 1289 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) { 1290 b_raid = newtButton(26, 6, "RAID.."); 1291 } 1292 newtPushHelpLine 1293 (" Edit this partition's mountpoint, size and format; then click 'OK'."); 1294 myForm = newtForm(NULL, NULL, 0); 1295 newtFormAddComponents(myForm, deviceComp, mountpointComp, sizeComp, 1296 formatComp, label0, label1, label2, label3, bOK, 1297 bCancel, b_raid, NULL); 1298 for (b_res = NULL; b_res != bOK && b_res != bCancel;) { 1299 b_res = newtRunForm(myForm); 1300 strcpy(device_str, device_here); 1301 strip_spaces(device_str); 1302 strcpy(mountpoint_str, mountpoint_here); 1303 strip_spaces(mountpoint_str); 1304 strcpy(format_str, format_here); 1305 strip_spaces(format_str); 1306 if (b_res == bOK && strstr(device_str, RAID_DEVICE_STUB) 1307 && strstr(device_used_to_be, RAID_DEVICE_STUB) 1308 && strcmp(device_str, device_used_to_be)) { 1309 popup_and_OK("You can't change /dev/mdX to /dev/mdY."); 1310 b_res = NULL; 1311 continue; 1312 } else if (b_res == bOK && !strcmp(mountpoint_str, "image") 1313 && strcmp(mountpt_used_to_be, "image")) { 1314 popup_and_OK("You can't change a regular device to an image."); 1315 b_res = NULL; 1316 continue; 1317 } 1318 if (!strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1319 && strcmp(mountlist->el[currline].mountpoint, "image")) { 1320 strcpy(size_str, size_here); 1321 strip_spaces(size_str); 1322 } else { 1323 sprintf(size_str, "%ld", 1324 calculate_raid_device_size(mountlist, raidlist, 1325 mountlist->el[currline]. 1326 device) / 1024); 1327 newtLabelSetText(sizeComp, size_str); 1328 } 1329 /* do not let user click RAID button if user has changed device_str */ 1330 if (b_res == b_raid) { 1331 if (strcmp(device_str, mountlist->el[currline].device)) { 1332 /* 1333 can't change mountlist's entry from /dex/mdX to /dev/mdY: it would ugly 1334 when you try to map the changes over to the raidtab list, trust me 1335 */ 1336 popup_and_OK 1337 ("You cannot edit the RAID settings until you have OK'd your change to the device node."); 1338 } else { 1339 j = find_raid_device_in_raidlist(raidlist, 1340 mountlist->el[currline]. 1341 device); 1342 if (j < 0) { 1343 sprintf(tmp, 1344 "/etc/raidtab does not have an entry for %s; please delete it and add it again", 1345 mountlist->el[currline].device); 1346 popup_and_OK(tmp); 1347 } else { 1348 log_it("edit_raidlist_entry - calling"); 1349 edit_raidlist_entry(mountlist, raidlist, 1350 &raidlist->el[j], currline); 1351 } 1352 } 1353 } 1354 } 1355 newtFormDestroy(myForm); 1356 newtPopHelpLine(); 1357 newtPopWindow(); 1358 if (b_res == bCancel) { 1359 memcpy((void *) raidlist, (void *) &bkp_raidlist, 1360 sizeof(struct raidlist_itself)); 1361 return; 1362 } 1363 strcpy(mountlist->el[currline].device, device_str); 1364 strcpy(mountlist->el[currline].mountpoint, mountpoint_str); 1365 strcpy(mountlist->el[currline].format, format_str); 1366 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1367 || !strcmp(mountlist->el[currline].mountpoint, "image")) { 1368 mountlist->el[currline].size = 1369 calculate_raid_device_size(mountlist, raidlist, 1370 mountlist->el[currline].device); 1371 } else { 1372 mountlist->el[currline].size = atol(size_str) * 1024; 1373 } 1374 newtListboxSetEntry(listbox, (int) keylist[currline], 1375 mountlist_entry_to_string(mountlist, currline)); 1376 /* if new /dev/md RAID device then do funky stuff */ 1377 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1378 && !strstr(device_used_to_be, RAID_DEVICE_STUB)) { 1379 initiate_new_raidlist_entry(raidlist, mountlist, currline, 1380 device_str); 1381 } 1382 /* if moving from RAID to non-RAID then do funky stuff */ 1383 else if (strstr(device_used_to_be, RAID_DEVICE_STUB) 1384 && !strstr(device_str, RAID_DEVICE_STUB)) { 1385 delete_raidlist_entry(mountlist, raidlist, device_str); 1386 } 1387 /* if moving a non-RAID to another non-RAID then re-jig any RAID disks, if necessary */ 1388 else if (!strstr(device_used_to_be, RAID_DEVICE_STUB) 1389 && !strstr(device_str, RAID_DEVICE_STUB)) { 1390 rejig_partition_name_in_raidlist_if_necessary(raidlist, 1391 device_used_to_be, 1392 device_str); 1393 } 1497 1394 /* else, moving a RAID to another RAID; bad idea, or so I thought */ 1498 #ifndef __FreeBSD__ /* It works fine under FBSD. */ 1499 else if (strcmp (device_used_to_be, device_str)) 1500 { 1501 popup_and_OK 1502 ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it."); 1503 } 1395 #ifndef __FreeBSD__ /* It works fine under FBSD. */ 1396 else if (strcmp(device_used_to_be, device_str)) { 1397 popup_and_OK 1398 ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it."); 1399 } 1504 1400 #endif 1505 redraw_mountlist(mountlist, keylist, listbox);1401 redraw_mountlist(mountlist, keylist, listbox); 1506 1402 } 1507 1403 … … 1517 1413 */ 1518 1414 void 1519 add_raid_subdisk (struct raidlist_itself *raidlist, struct vinum_plex *raidrec, char *temp) 1520 { 1521 int i; 1522 bool found = FALSE; 1523 1524 for (i = 0; i < raidlist->disks.entries; ++i) { 1525 if (!strcmp (raidlist->disks.el[i].device, temp)) { 1526 strcpy (raidrec->sd [raidrec->subdisks].which_device, 1527 raidlist->disks.el[i].name); 1528 found = TRUE; 1529 } 1530 } 1531 if (!found) { 1532 sprintf (raidlist->disks.el[raidlist->disks.entries].name, "drive%i", raidlist->disks.entries); 1533 sprintf (raidrec->sd [raidrec->subdisks].which_device, "drive%i", raidlist->disks.entries); 1534 strcpy (raidlist->disks.el[raidlist->disks.entries++].device, temp); 1535 } 1536 raidrec->subdisks++; 1415 add_raid_subdisk(struct raidlist_itself *raidlist, 1416 struct vinum_plex *raidrec, char *temp) 1417 { 1418 int i; 1419 bool found = FALSE; 1420 1421 for (i = 0; i < raidlist->disks.entries; ++i) { 1422 if (!strcmp(raidlist->disks.el[i].device, temp)) { 1423 strcpy(raidrec->sd[raidrec->subdisks].which_device, 1424 raidlist->disks.el[i].name); 1425 found = TRUE; 1426 } 1427 } 1428 if (!found) { 1429 sprintf(raidlist->disks.el[raidlist->disks.entries].name, 1430 "drive%i", raidlist->disks.entries); 1431 sprintf(raidrec->sd[raidrec->subdisks].which_device, "drive%i", 1432 raidlist->disks.entries); 1433 strcpy(raidlist->disks.el[raidlist->disks.entries++].device, temp); 1434 } 1435 raidrec->subdisks++; 1537 1436 } 1538 1437 … … 1547 1446 * @ingroup restoreUtilityGroup 1548 1447 */ 1549 char * 1550 find_dev_entry_for_raid_device_name (struct raidlist_itself *raidlist, char *vinum_name) 1551 { 1552 1553 1554 if (!strcmp(raidlist->disks.el[i].name, vinum_name)) {1555 1556 }1557 1558 1448 char *find_dev_entry_for_raid_device_name(struct raidlist_itself *raidlist, 1449 char *vinum_name) 1450 { 1451 int i; 1452 for (i = 0; i < raidlist->disks.entries; ++i) { 1453 if (!strcmp(raidlist->disks.el[i].name, vinum_name)) { 1454 return raidlist->disks.el[i].device; 1455 } 1456 } 1457 return NULL; 1559 1458 } 1560 1459 1561 1460 void 1562 edit_raidlist_plex (struct mountlist_itself *mountlist, 1563 struct raidlist_itself *raidlist, 1564 struct vinum_plex *raidrec, int currline, int currline2); 1461 edit_raidlist_plex(struct mountlist_itself *mountlist, 1462 struct raidlist_itself *raidlist, 1463 struct vinum_plex *raidrec, int currline, 1464 int currline2); 1565 1465 1566 1466 #endif … … 1576 1476 */ 1577 1477 void 1578 edit_raidlist_entry (struct mountlist_itself *mountlist, 1579 struct raidlist_itself *raidlist, 1580 struct OSSWAP (raid_device_record, vinum_volume) *raidrec, int currline) 1478 edit_raidlist_entry(struct mountlist_itself *mountlist, 1479 struct raidlist_itself *raidlist, 1480 struct OSSWAP (raid_device_record, 1481 vinum_volume) * raidrec, int currline) 1581 1482 { 1582 1483 1583 1484 #ifdef __FreeBSD__ 1584 1485 /** structures ********************************************************/ 1585 1486 struct vinum_volume bkp_raidrec; 1586 1487 1587 1488 1588 1489 /** buffers ***********************************************************/ 1589 1490 char title_of_editraidForm_window[MAX_STR_LEN]; 1590 1491 1591 1492 /** newt **************************************************************/ 1592 newtComponent editraidForm; 1593 newtComponent bOK; 1594 newtComponent bCancel; 1595 newtComponent bEdit; 1596 newtComponent bAdd; 1597 newtComponent bDelete; 1598 newtComponent b_res; 1599 newtComponent plexesListbox; 1600 newtComponent plexesHeader; 1601 1602 void *keylist[10]; 1603 void *curr_choice; 1604 1605 int currline2 = 0; 1606 1607 log_it ("Started edit_raidlist_entry"); 1608 memcpy ((void *) &bkp_raidrec, (void *) raidrec, 1609 sizeof (struct vinum_volume)); 1610 sprintf (title_of_editraidForm_window, "Plexes on %s", raidrec->volname); 1611 newtPushHelpLine (" Please select a plex to edit"); 1612 newtOpenWindow (13, 5, 54, 15, title_of_editraidForm_window); 1613 for (;;) 1614 { 1615 int i; 1616 char headerstr[MAX_STR_LEN]; 1617 snprintf (headerstr, MAX_STR_LEN, "%-14s %-8s %11s %8s", 1618 "Plex", "Level", "Stripe Size", "Subdisks"); 1619 1620 bOK = newtCompactButton (2, 13, " OK "); 1621 bCancel = newtCompactButton (12, 13, "Cancel"); 1622 bAdd = newtCompactButton (22, 13, " Add "); 1623 bEdit = newtCompactButton (32, 13, " Edit "); 1624 bDelete = newtCompactButton (42, 13, "Delete"); 1625 1626 plexesListbox = newtListbox (2, 3, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1627 plexesHeader = newtLabel (2, 2, headerstr); 1628 editraidForm = newtForm (NULL, NULL, 0); 1629 1630 newtListboxClear (plexesListbox); 1631 for (i = 0; i < 10; ++i) { 1632 keylist[i] = (void *) i; 1633 if (i < raidrec->plexes) { 1634 char pname[64], entry[MAX_STR_LEN], raidlevel[64], chunksize[64]; 1635 switch (raidrec->plex[i].raidlevel) { 1636 case -1: 1637 strcpy (raidlevel, "concat"); 1638 break; 1639 case 0: 1640 strcpy (raidlevel, "striped"); 1641 break; 1642 case 5: 1643 strcpy (raidlevel, "raid5"); 1644 break; 1645 default: 1646 sprintf (raidlevel, "raid%i", raidrec->plex[i].raidlevel); 1647 break; 1648 } 1649 1650 if (raidrec->plex[i].raidlevel == -1) { 1651 strcpy (chunksize, "N/A"); 1652 } else { 1653 sprintf (chunksize, "%dk", raidrec->plex[i].stripesize); 1654 } 1655 snprintf (pname, 64, "%s.p%i", raidrec->volname, i); 1656 snprintf (entry, MAX_STR_LEN, "%-14s %-8s %11s %8d", pname, raidlevel, chunksize, 1657 raidrec->plex[i].subdisks); 1658 newtListboxAppendEntry (plexesListbox, entry, keylist[i]); 1659 } 1660 } 1661 1662 newtFormAddComponents (editraidForm, bOK, bCancel, bAdd, bEdit, 1663 bDelete, plexesListbox, plexesHeader, NULL); 1664 1665 b_res = newtRunForm (editraidForm); 1666 if (b_res == bOK || b_res == bCancel) 1667 { 1668 break; 1669 } 1670 1671 curr_choice = newtListboxGetCurrent (plexesListbox); 1672 for (currline2 = 0; currline2 < raidrec->plexes; ++currline2) { 1673 if (currline2 > 9) break; 1674 if (keylist[currline2] == curr_choice) break; 1675 } 1676 1677 if (b_res == bDelete) { 1678 char msg[MAX_STR_LEN]; 1679 sprintf (msg, "Are you sure you want to delete %s.p%i?", raidrec->volname, currline2); 1680 if (ask_me_yes_or_no (msg)) { 1681 log_it ("Deleting RAID plex"); 1682 memcpy ((void *) &raidrec->plex[currline2], 1683 (void *) &raidrec->plex[raidrec->plexes - 1], 1684 sizeof (struct vinum_plex)); 1685 raidrec->plexes--; 1686 } 1687 continue; 1688 } 1689 if (b_res == bAdd) { 1690 raidrec->plex[raidrec->plexes].raidlevel = 0; 1691 raidrec->plex[raidrec->plexes].stripesize = 279; 1692 raidrec->plex[raidrec->plexes].subdisks = 0; 1693 currline2 = raidrec->plexes++; 1694 } 1695 edit_raidlist_plex (mountlist, raidlist, &raidrec->plex[currline2], currline, currline2); 1696 newtFormDestroy (editraidForm); 1697 } 1698 if (b_res == bCancel) 1699 { 1700 memcpy ((void *) raidrec, (void *) &bkp_raidrec, 1701 sizeof (struct vinum_volume)); 1702 } 1703 newtPopHelpLine (); 1704 newtPopWindow (); 1705 mountlist->el[currline].size = 1706 calculate_raid_device_size (mountlist, raidlist, raidrec->volname); 1493 newtComponent editraidForm; 1494 newtComponent bOK; 1495 newtComponent bCancel; 1496 newtComponent bEdit; 1497 newtComponent bAdd; 1498 newtComponent bDelete; 1499 newtComponent b_res; 1500 newtComponent plexesListbox; 1501 newtComponent plexesHeader; 1502 1503 void *keylist[10]; 1504 void *curr_choice; 1505 1506 int currline2 = 0; 1507 1508 log_it("Started edit_raidlist_entry"); 1509 memcpy((void *) &bkp_raidrec, (void *) raidrec, 1510 sizeof(struct vinum_volume)); 1511 sprintf(title_of_editraidForm_window, "Plexes on %s", 1512 raidrec->volname); 1513 newtPushHelpLine(" Please select a plex to edit"); 1514 newtOpenWindow(13, 5, 54, 15, title_of_editraidForm_window); 1515 for (;;) { 1516 int i; 1517 char headerstr[MAX_STR_LEN]; 1518 snprintf(headerstr, MAX_STR_LEN, "%-14s %-8s %11s %8s", 1519 "Plex", "Level", "Stripe Size", "Subdisks"); 1520 1521 bOK = newtCompactButton(2, 13, " OK "); 1522 bCancel = newtCompactButton(12, 13, "Cancel"); 1523 bAdd = newtCompactButton(22, 13, " Add "); 1524 bEdit = newtCompactButton(32, 13, " Edit "); 1525 bDelete = newtCompactButton(42, 13, "Delete"); 1526 1527 plexesListbox = 1528 newtListbox(2, 3, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1529 plexesHeader = newtLabel(2, 2, headerstr); 1530 editraidForm = newtForm(NULL, NULL, 0); 1531 1532 newtListboxClear(plexesListbox); 1533 for (i = 0; i < 10; ++i) { 1534 keylist[i] = (void *) i; 1535 if (i < raidrec->plexes) { 1536 char pname[64], entry[MAX_STR_LEN], raidlevel[64], 1537 chunksize[64]; 1538 switch (raidrec->plex[i].raidlevel) { 1539 case -1: 1540 strcpy(raidlevel, "concat"); 1541 break; 1542 case 0: 1543 strcpy(raidlevel, "striped"); 1544 break; 1545 case 5: 1546 strcpy(raidlevel, "raid5"); 1547 break; 1548 default: 1549 sprintf(raidlevel, "raid%i", 1550 raidrec->plex[i].raidlevel); 1551 break; 1552 } 1553 1554 if (raidrec->plex[i].raidlevel == -1) { 1555 strcpy(chunksize, "N/A"); 1556 } else { 1557 sprintf(chunksize, "%dk", raidrec->plex[i].stripesize); 1558 } 1559 snprintf(pname, 64, "%s.p%i", raidrec->volname, i); 1560 snprintf(entry, MAX_STR_LEN, "%-14s %-8s %11s %8d", 1561 pname, raidlevel, chunksize, 1562 raidrec->plex[i].subdisks); 1563 newtListboxAppendEntry(plexesListbox, entry, keylist[i]); 1564 } 1565 } 1566 1567 newtFormAddComponents(editraidForm, bOK, bCancel, bAdd, bEdit, 1568 bDelete, plexesListbox, plexesHeader, NULL); 1569 1570 b_res = newtRunForm(editraidForm); 1571 if (b_res == bOK || b_res == bCancel) { 1572 break; 1573 } 1574 1575 curr_choice = newtListboxGetCurrent(plexesListbox); 1576 for (currline2 = 0; currline2 < raidrec->plexes; ++currline2) { 1577 if (currline2 > 9) 1578 break; 1579 if (keylist[currline2] == curr_choice) 1580 break; 1581 } 1582 1583 if (b_res == bDelete) { 1584 char msg[MAX_STR_LEN]; 1585 sprintf(msg, "Are you sure you want to delete %s.p%i?", 1586 raidrec->volname, currline2); 1587 if (ask_me_yes_or_no(msg)) { 1588 log_it("Deleting RAID plex"); 1589 memcpy((void *) &raidrec->plex[currline2], 1590 (void *) &raidrec->plex[raidrec->plexes - 1], 1591 sizeof(struct vinum_plex)); 1592 raidrec->plexes--; 1593 } 1594 continue; 1595 } 1596 if (b_res == bAdd) { 1597 raidrec->plex[raidrec->plexes].raidlevel = 0; 1598 raidrec->plex[raidrec->plexes].stripesize = 279; 1599 raidrec->plex[raidrec->plexes].subdisks = 0; 1600 currline2 = raidrec->plexes++; 1601 } 1602 edit_raidlist_plex(mountlist, raidlist, &raidrec->plex[currline2], 1603 currline, currline2); 1604 newtFormDestroy(editraidForm); 1605 } 1606 if (b_res == bCancel) { 1607 memcpy((void *) raidrec, (void *) &bkp_raidrec, 1608 sizeof(struct vinum_volume)); 1609 } 1610 newtPopHelpLine(); 1611 newtPopWindow(); 1612 mountlist->el[currline].size = 1613 calculate_raid_device_size(mountlist, raidlist, raidrec->volname); 1707 1614 #else 1708 1615 /** structures ********************************************************/ 1709 1616 struct raid_device_record *bkp_raidrec; 1710 1617 1711 1618 1712 1619 /** buffers ***********************************************************/ 1713 1620 char *title_of_editraidForm_window; 1714 1621 char *sz_raid_level; 1715 1622 char *sz_data_disks; … … 1719 1626 1720 1627 /** newt **************************************************************/ 1721 1628 newtComponent editraidForm; 1722 1629 newtComponent bOK; 1723 1630 newtComponent bCancel; … … 1730 1637 newtComponent b_res; 1731 1638 1732 assert(mountlist!=NULL); 1733 assert(raidlist!=NULL); 1734 assert(raidrec!=NULL); 1735 1736 malloc_string(title_of_editraidForm_window); 1737 malloc_string(sz_raid_level); 1738 malloc_string(sz_data_disks); 1739 malloc_string(sz_spare_disks); 1740 malloc_string(sz_parity_disks); 1741 malloc_string(sz_failed_disks); 1742 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) 1743 { fatal_error("Cannot malloc space for raidrec"); } 1744 1745 log_it ("Started edit_raidlist_entry"); 1746 1747 memcpy ((void *) bkp_raidrec, (void *) raidrec, 1748 sizeof (struct raid_device_record)); 1749 sprintf (title_of_editraidForm_window, "%s", raidrec->raid_device); 1750 log_msg(2, "Opening newt window"); 1751 newtOpenWindow (20, 5, 40, 14, title_of_editraidForm_window); 1752 for (;;) 1753 { 1754 log_msg(2, "Main loop"); 1755 sprintf (title_of_editraidForm_window, "Edit %s", raidrec->raid_device); 1756 strcpy (sz_raid_level, 1757 turn_raid_level_number_to_string (raidrec->raid_level)); 1758 strcpy (sz_data_disks, 1759 number_of_disks_as_string (raidrec->data_disks.entries, 1760 "data")); 1761 strcpy (sz_spare_disks, 1762 number_of_disks_as_string (raidrec->spare_disks.entries, 1763 "spare")); 1764 strcpy (sz_parity_disks, 1765 number_of_disks_as_string (raidrec->parity_disks.entries, 1766 "parity")); 1767 strcpy (sz_failed_disks, 1768 number_of_disks_as_string (raidrec->failed_disks.entries, 1769 "failed")); 1770 bSelectData = newtButton (1, 1, sz_data_disks); 1771 bSelectSpare = newtButton (20, 1, sz_spare_disks); 1772 bSelectParity = newtButton (1, 5, sz_parity_disks); 1773 bSelectFailed = newtButton (20, 5, sz_failed_disks); 1774 bChangeRaid = newtButton (1, 9, sz_raid_level); 1775 bOK = newtButton (16 + (raidrec->raid_level == -1), 9, " OK "); 1776 bCancel = newtButton (28, 9, "Cancel"); 1777 bAdditional = 1778 newtCompactButton (1, 13, "Additional settings and information"); 1779 newtPushHelpLine 1780 (" Edit the RAID device's settings to your heart's content, then hit OK/Cancel."); 1781 editraidForm = newtForm (NULL, NULL, 0); 1782 newtFormAddComponents (editraidForm, bSelectData, bSelectParity, 1783 bChangeRaid, bSelectSpare, bSelectFailed, bOK, 1784 bCancel, bAdditional); 1785 b_res = newtRunForm (editraidForm); 1786 if (b_res == bChangeRaid) 1787 { 1788 choose_raid_level (raidrec); 1789 } 1790 else if (b_res == bSelectData) 1791 { 1792 select_raid_disks (mountlist, raidlist, raidrec, "data", 1793 &raidrec->data_disks); 1794 } 1795 else if (b_res == bSelectSpare) 1796 { 1797 select_raid_disks (mountlist, raidlist, raidrec, "spare", 1798 &raidrec->spare_disks); 1799 } 1800 else if (b_res == bSelectParity) 1801 { 1802 select_raid_disks (mountlist, raidlist, raidrec, "parity", 1803 &raidrec->parity_disks); 1804 } 1805 else if (b_res == bSelectFailed) 1806 { 1807 select_raid_disks (mountlist, raidlist, raidrec, "failed", 1808 &raidrec->failed_disks); 1809 } 1810 else if (b_res == bAdditional) 1811 { 1812 edit_raidrec_additional_vars (raidrec); 1813 } 1814 newtFormDestroy (editraidForm); 1815 if (b_res == bOK || b_res == bCancel) 1816 { 1817 break; 1818 } 1819 } 1820 if (b_res == bCancel) 1821 { 1822 memcpy ((void *) raidrec, (void *) bkp_raidrec, 1823 sizeof (struct raid_device_record)); 1824 } 1825 newtPopHelpLine (); 1826 newtPopWindow (); 1827 mountlist->el[currline].size = 1828 calculate_raid_device_size (mountlist, raidlist, raidrec->raid_device); 1829 paranoid_free(title_of_editraidForm_window); 1830 paranoid_free(sz_raid_level); 1831 paranoid_free(sz_data_disks); 1832 paranoid_free(sz_spare_disks); 1833 paranoid_free(sz_parity_disks); 1834 paranoid_free(sz_failed_disks); 1835 paranoid_free(bkp_raidrec); 1639 assert(mountlist != NULL); 1640 assert(raidlist != NULL); 1641 assert(raidrec != NULL); 1642 1643 malloc_string(title_of_editraidForm_window); 1644 malloc_string(sz_raid_level); 1645 malloc_string(sz_data_disks); 1646 malloc_string(sz_spare_disks); 1647 malloc_string(sz_parity_disks); 1648 malloc_string(sz_failed_disks); 1649 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) { 1650 fatal_error("Cannot malloc space for raidrec"); 1651 } 1652 1653 log_it("Started edit_raidlist_entry"); 1654 1655 memcpy((void *) bkp_raidrec, (void *) raidrec, 1656 sizeof(struct raid_device_record)); 1657 sprintf(title_of_editraidForm_window, "%s", raidrec->raid_device); 1658 log_msg(2, "Opening newt window"); 1659 newtOpenWindow(20, 5, 40, 14, title_of_editraidForm_window); 1660 for (;;) { 1661 log_msg(2, "Main loop"); 1662 sprintf(title_of_editraidForm_window, "Edit %s", 1663 raidrec->raid_device); 1664 strcpy(sz_raid_level, 1665 turn_raid_level_number_to_string(raidrec->raid_level)); 1666 strcpy(sz_data_disks, 1667 number_of_disks_as_string(raidrec->data_disks.entries, 1668 "data")); 1669 strcpy(sz_spare_disks, 1670 number_of_disks_as_string(raidrec->spare_disks.entries, 1671 "spare")); 1672 strcpy(sz_parity_disks, 1673 number_of_disks_as_string(raidrec->parity_disks.entries, 1674 "parity")); 1675 strcpy(sz_failed_disks, 1676 number_of_disks_as_string(raidrec->failed_disks.entries, 1677 "failed")); 1678 bSelectData = newtButton(1, 1, sz_data_disks); 1679 bSelectSpare = newtButton(20, 1, sz_spare_disks); 1680 bSelectParity = newtButton(1, 5, sz_parity_disks); 1681 bSelectFailed = newtButton(20, 5, sz_failed_disks); 1682 bChangeRaid = newtButton(1, 9, sz_raid_level); 1683 bOK = newtButton(16 + (raidrec->raid_level == -1), 9, " OK "); 1684 bCancel = newtButton(28, 9, "Cancel"); 1685 bAdditional = 1686 newtCompactButton(1, 13, 1687 "Additional settings and information"); 1688 newtPushHelpLine 1689 (" Edit the RAID device's settings to your heart's content, then hit OK/Cancel."); 1690 editraidForm = newtForm(NULL, NULL, 0); 1691 newtFormAddComponents(editraidForm, bSelectData, bSelectParity, 1692 bChangeRaid, bSelectSpare, bSelectFailed, 1693 bOK, bCancel, bAdditional); 1694 b_res = newtRunForm(editraidForm); 1695 if (b_res == bChangeRaid) { 1696 choose_raid_level(raidrec); 1697 } else if (b_res == bSelectData) { 1698 select_raid_disks(mountlist, raidlist, raidrec, "data", 1699 &raidrec->data_disks); 1700 } else if (b_res == bSelectSpare) { 1701 select_raid_disks(mountlist, raidlist, raidrec, "spare", 1702 &raidrec->spare_disks); 1703 } else if (b_res == bSelectParity) { 1704 select_raid_disks(mountlist, raidlist, raidrec, "parity", 1705 &raidrec->parity_disks); 1706 } else if (b_res == bSelectFailed) { 1707 select_raid_disks(mountlist, raidlist, raidrec, "failed", 1708 &raidrec->failed_disks); 1709 } else if (b_res == bAdditional) { 1710 edit_raidrec_additional_vars(raidrec); 1711 } 1712 newtFormDestroy(editraidForm); 1713 if (b_res == bOK || b_res == bCancel) { 1714 break; 1715 } 1716 } 1717 if (b_res == bCancel) { 1718 memcpy((void *) raidrec, (void *) bkp_raidrec, 1719 sizeof(struct raid_device_record)); 1720 } 1721 newtPopHelpLine(); 1722 newtPopWindow(); 1723 mountlist->el[currline].size = 1724 calculate_raid_device_size(mountlist, raidlist, 1725 raidrec->raid_device); 1726 paranoid_free(title_of_editraidForm_window); 1727 paranoid_free(sz_raid_level); 1728 paranoid_free(sz_data_disks); 1729 paranoid_free(sz_spare_disks); 1730 paranoid_free(sz_parity_disks); 1731 paranoid_free(sz_failed_disks); 1732 paranoid_free(bkp_raidrec); 1836 1733 #endif 1837 1734 } … … 1850 1747 */ 1851 1748 void 1852 edit_raidlist_plex 1853 1854 1749 edit_raidlist_plex(struct mountlist_itself *mountlist, 1750 struct raidlist_itself *raidlist, 1751 struct vinum_plex *raidrec, int currline, int currline2) 1855 1752 { 1856 1753 1857 1754 /** structures ********************************************************/ 1858 1755 struct vinum_plex bkp_raidrec; 1859 1756 1860 1757 1861 1758 /** buffers ***********************************************************/ 1862 1759 char title_of_editraidForm_window[MAX_STR_LEN]; 1863 1760 1864 1761 /** newt **************************************************************/ 1865 newtComponent editraidForm; 1866 newtComponent bOK; 1867 newtComponent bCancel; 1868 newtComponent bEdit; 1869 newtComponent bAdd; 1870 newtComponent bDelete; 1871 newtComponent b_res; 1872 newtComponent unallocListbox, allocListbox; 1873 newtComponent bLevel, sLevel; 1874 newtComponent bStripeSize, sStripeSize; 1875 newtComponent bAlloc, bUnalloc; 1876 1877 void *keylist[ARBITRARY_MAXIMUM]; 1878 void *curr_choice_a, *curr_choice_u; 1879 int currline_a, currline_u; 1880 1881 struct mountlist_itself *unallocparts; 1882 1883 unallocparts = malloc (sizeof (struct mountlist_itself)); 1884 1885 log_it ("Started edit_raidlist_entry"); 1886 memcpy ((void *) &bkp_raidrec, (void *) raidrec, 1887 sizeof (struct vinum_plex)); 1888 sprintf (title_of_editraidForm_window, "%s.p%i", raidlist->el[currline].volname, currline2); 1889 newtPushHelpLine (" Please select a subdisk to edit, or edit this plex's parameters"); 1890 newtOpenWindow (13, 3, 54, 18, title_of_editraidForm_window); 1891 for (;;) 1892 { 1893 int i; 1894 char headerstr[MAX_STR_LEN]; 1895 char tmp[64]; 1896 snprintf (headerstr, MAX_STR_LEN, "%-24s %s", 1897 "Subdisk", "Device"); 1898 1899 1900 switch (raidrec->raidlevel) { 1901 case -1: 1902 strcpy (tmp, "concat"); 1903 break; 1904 case 0: 1905 strcpy (tmp, "striped"); 1906 break; 1907 case 5: 1908 strcpy (tmp, "raid5"); 1909 break; 1910 default: 1911 sprintf (tmp, "unknown (%i)", raidrec->raidlevel); 1912 break; 1913 } 1914 bLevel = newtCompactButton (2, 2, " RAID level "); 1915 sLevel = newtLabel (19, 2, tmp); 1916 1917 if (raidrec->raidlevel >= 0) { 1918 sprintf (tmp, "%ik", raidrec->stripesize); 1919 bStripeSize = newtCompactButton (2, 4, " Stripe size "); 1920 } else { 1921 strcpy (tmp, "N/A"); 1922 bStripeSize = newtLabel (2, 4, "Stripe size:"); 1923 } 1924 sStripeSize = newtLabel (19, 4, tmp); 1925 1926 bOK = newtCompactButton (2, 16, " OK "); 1927 bCancel = newtCompactButton (12, 16, "Cancel"); 1928 bAdd = newtCompactButton (22, 16, " Add "); 1929 bEdit = newtCompactButton (32, 16, " Edit "); 1930 bDelete = newtCompactButton (42, 16, "Delete"); 1931 1932 1933 // plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1934 // plexesHeader = newtLabel (2, 6, headerstr); 1935 unallocListbox = newtListbox (2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1936 allocListbox = newtListbox (33, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1937 bAlloc = newtButton (23, 7, " -> "); 1938 bUnalloc = newtButton (23, 11, " <- "); 1939 1940 editraidForm = newtForm (NULL, NULL, 0); 1941 1942 newtListboxClear (allocListbox); 1943 newtListboxClear (unallocListbox); 1944 bzero (unallocparts, sizeof (struct mountlist_itself)); 1945 make_list_of_unallocated_raid_partitions (unallocparts, mountlist, raidlist); 1946 for (i = 0; i < ARBITRARY_MAXIMUM; ++i) { 1947 char entry[MAX_STR_LEN]; 1948 keylist[i] = (void *) i; 1949 if (i < raidrec->subdisks) { 1950 snprintf (entry, MAX_STR_LEN, "%-17s", find_dev_entry_for_raid_device_name (raidlist, raidrec->sd[i].which_device)); 1951 newtListboxAppendEntry (allocListbox, entry, keylist[i]); 1952 } 1953 if (i < unallocparts->entries) { 1954 snprintf (entry, MAX_STR_LEN, "%-17s", unallocparts->el[i].device); 1955 newtListboxAppendEntry (unallocListbox, entry, keylist[i]); 1956 } 1957 } 1958 1762 newtComponent editraidForm; 1763 newtComponent bOK; 1764 newtComponent bCancel; 1765 newtComponent bEdit; 1766 newtComponent bAdd; 1767 newtComponent bDelete; 1768 newtComponent b_res; 1769 newtComponent unallocListbox, allocListbox; 1770 newtComponent bLevel, sLevel; 1771 newtComponent bStripeSize, sStripeSize; 1772 newtComponent bAlloc, bUnalloc; 1773 1774 void *keylist[ARBITRARY_MAXIMUM]; 1775 void *curr_choice_a, *curr_choice_u; 1776 int currline_a, currline_u; 1777 1778 struct mountlist_itself *unallocparts; 1779 1780 unallocparts = malloc(sizeof(struct mountlist_itself)); 1781 1782 log_it("Started edit_raidlist_entry"); 1783 memcpy((void *) &bkp_raidrec, (void *) raidrec, 1784 sizeof(struct vinum_plex)); 1785 sprintf(title_of_editraidForm_window, "%s.p%i", 1786 raidlist->el[currline].volname, currline2); 1787 newtPushHelpLine 1788 (" Please select a subdisk to edit, or edit this plex's parameters"); 1789 newtOpenWindow(13, 3, 54, 18, title_of_editraidForm_window); 1790 for (;;) { 1791 int i; 1792 char headerstr[MAX_STR_LEN]; 1793 char tmp[64]; 1794 snprintf(headerstr, MAX_STR_LEN, "%-24s %s", "Subdisk", "Device"); 1795 1796 1797 switch (raidrec->raidlevel) { 1798 case -1: 1799 strcpy(tmp, "concat"); 1800 break; 1801 case 0: 1802 strcpy(tmp, "striped"); 1803 break; 1804 case 5: 1805 strcpy(tmp, "raid5"); 1806 break; 1807 default: 1808 sprintf(tmp, "unknown (%i)", raidrec->raidlevel); 1809 break; 1810 } 1811 bLevel = newtCompactButton(2, 2, " RAID level "); 1812 sLevel = newtLabel(19, 2, tmp); 1813 1814 if (raidrec->raidlevel >= 0) { 1815 sprintf(tmp, "%ik", raidrec->stripesize); 1816 bStripeSize = newtCompactButton(2, 4, " Stripe size "); 1817 } else { 1818 strcpy(tmp, "N/A"); 1819 bStripeSize = newtLabel(2, 4, "Stripe size:"); 1820 } 1821 sStripeSize = newtLabel(19, 4, tmp); 1822 1823 bOK = newtCompactButton(2, 16, " OK "); 1824 bCancel = newtCompactButton(12, 16, "Cancel"); 1825 bAdd = newtCompactButton(22, 16, " Add "); 1826 bEdit = newtCompactButton(32, 16, " Edit "); 1827 bDelete = newtCompactButton(42, 16, "Delete"); 1828 1829 1830 // plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1831 // plexesHeader = newtLabel (2, 6, headerstr); 1832 unallocListbox = 1833 newtListbox(2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1834 allocListbox = 1835 newtListbox(33, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1836 bAlloc = newtButton(23, 7, " -> "); 1837 bUnalloc = newtButton(23, 11, " <- "); 1838 1839 editraidForm = newtForm(NULL, NULL, 0); 1840 1841 newtListboxClear(allocListbox); 1842 newtListboxClear(unallocListbox); 1843 bzero(unallocparts, sizeof(struct mountlist_itself)); 1844 make_list_of_unallocated_raid_partitions(unallocparts, mountlist, 1845 raidlist); 1846 for (i = 0; i < ARBITRARY_MAXIMUM; ++i) { 1847 char entry[MAX_STR_LEN]; 1848 keylist[i] = (void *) i; 1849 if (i < raidrec->subdisks) { 1850 snprintf(entry, MAX_STR_LEN, "%-17s", 1851 find_dev_entry_for_raid_device_name(raidlist, 1852 raidrec-> 1853 sd[i]. 1854 which_device)); 1855 newtListboxAppendEntry(allocListbox, entry, keylist[i]); 1856 } 1857 if (i < unallocparts->entries) { 1858 snprintf(entry, MAX_STR_LEN, "%-17s", 1859 unallocparts->el[i].device); 1860 newtListboxAppendEntry(unallocListbox, entry, keylist[i]); 1861 } 1862 } 1863 1959 1864 #define COMP(x) newtFormAddComponent (editraidForm, x) 1960 1865 #define UCOMP(x) if (unallocparts->entries > 0) COMP(x) 1961 1866 #define ACOMP(x) if (raidrec->subdisks > 0) COMP(x) 1962 editraidForm = newtForm(NULL, NULL, 0);1963 UCOMP(unallocListbox);1964 UCOMP(bAlloc);1965 ACOMP(allocListbox);1966 ACOMP(bUnalloc);1967 COMP(bOK);1968 COMP(bCancel);1969 COMP(bLevel);1970 COMP(sLevel);1971 if (raidrec->raidlevel != -1) {1972 COMP(bStripeSize);1973 COMP(sStripeSize);1974 }1867 editraidForm = newtForm(NULL, NULL, 0); 1868 UCOMP(unallocListbox); 1869 UCOMP(bAlloc); 1870 ACOMP(allocListbox); 1871 ACOMP(bUnalloc); 1872 COMP(bOK); 1873 COMP(bCancel); 1874 COMP(bLevel); 1875 COMP(sLevel); 1876 if (raidrec->raidlevel != -1) { 1877 COMP(bStripeSize); 1878 COMP(sStripeSize); 1879 } 1975 1880 #undef COMP 1976 1881 #undef UCOMP 1977 1882 #undef ACOMP 1978 1883 1884 newtRefresh(); 1885 b_res = newtRunForm(editraidForm); 1886 if (b_res == bOK || b_res == bCancel) { 1887 break; 1888 } 1889 1890 curr_choice_a = (raidrec->subdisks > 0) ? 1891 newtListboxGetCurrent(allocListbox) : (void *) 1234; 1892 curr_choice_u = (unallocparts->entries > 0) ? 1893 newtListboxGetCurrent(unallocListbox) : (void *) 1234; 1894 for (currline_a = 0; currline_a < raidrec->subdisks; ++currline_a) { 1895 if (currline_a > ARBITRARY_MAXIMUM) 1896 break; 1897 if (keylist[currline_a] == curr_choice_a) 1898 break; 1899 } 1900 for (currline_u = 0; currline_u < unallocparts->entries; 1901 ++currline_u) { 1902 if (currline_u > ARBITRARY_MAXIMUM) 1903 break; 1904 if (keylist[currline_u] == curr_choice_u) 1905 break; 1906 } 1907 if (b_res == bLevel) { 1908 choose_raid_level(raidrec); 1909 } else if (b_res == bStripeSize) { 1910 char tmp[64]; 1911 sprintf(tmp, "%i", raidrec->stripesize); 1912 if (popup_and_get_string 1913 ("Stripe size", 1914 "Please enter the stripe size in kilobytes.", tmp, 20)) { 1915 raidrec->stripesize = atoi(tmp); 1916 } 1917 } else if ((b_res == bAlloc) || (b_res == unallocListbox)) { 1918 if (currline_u <= unallocparts->entries) 1919 add_raid_subdisk(raidlist, raidrec, 1920 unallocparts->el[currline_u].device); 1921 } else if ((b_res == bUnalloc) || (b_res == allocListbox)) { 1922 if (currline_a <= raidrec->subdisks) { 1923 memcpy((void *) &raidrec->sd[currline_a], 1924 (void *) &raidrec->sd[raidrec->subdisks - 1], 1925 sizeof(struct vinum_subdisk)); 1926 raidrec->subdisks--; 1927 } 1928 } 1929 #if 0 1930 } else { 1931 edit_raid_subdisk(raidlist, raidrec, &raidrec->sd[currline3], 1932 currline3); 1933 } 1934 #endif 1935 newtFormDestroy(editraidForm); 1979 1936 newtRefresh(); 1980 b_res = newtRunForm (editraidForm); 1981 if (b_res == bOK || b_res == bCancel) 1982 { 1983 break; 1984 } 1985 1986 curr_choice_a = (raidrec->subdisks > 0) ? 1987 newtListboxGetCurrent (allocListbox) : (void *)1234; 1988 curr_choice_u = (unallocparts->entries > 0) ? 1989 newtListboxGetCurrent (unallocListbox) : (void *)1234; 1990 for (currline_a = 0; currline_a < raidrec->subdisks; ++currline_a) { 1991 if (currline_a > ARBITRARY_MAXIMUM) break; 1992 if (keylist[currline_a] == curr_choice_a) break; 1993 } 1994 for (currline_u = 0; currline_u < unallocparts->entries; ++currline_u) { 1995 if (currline_u > ARBITRARY_MAXIMUM) break; 1996 if (keylist[currline_u] == curr_choice_u) break; 1997 } 1998 if (b_res == bLevel) { 1999 choose_raid_level (raidrec); 2000 } 2001 else if (b_res == bStripeSize) { 2002 char tmp[64]; 2003 sprintf (tmp, "%i", raidrec->stripesize); 2004 if (popup_and_get_string ("Stripe size", "Please enter the stripe size in kilobytes.", 2005 tmp, 20)) { 2006 raidrec->stripesize = atoi (tmp); 2007 } 2008 } 2009 else if ((b_res == bAlloc) || (b_res == unallocListbox)) { 2010 if (currline_u <= unallocparts->entries) 2011 add_raid_subdisk (raidlist, raidrec, unallocparts->el[currline_u].device); 2012 } 2013 else if ((b_res == bUnalloc) || (b_res == allocListbox)) { 2014 if (currline_a <= raidrec->subdisks) { 2015 memcpy ((void *) &raidrec->sd[currline_a], 2016 (void *) &raidrec->sd[raidrec->subdisks - 1], 2017 sizeof (struct vinum_subdisk)); 2018 raidrec->subdisks--; 2019 } 2020 } 2021 #if 0 2022 } else { 2023 edit_raid_subdisk (raidlist, raidrec, &raidrec->sd[currline3], currline3); 2024 } 2025 #endif 2026 newtFormDestroy (editraidForm); 2027 newtRefresh(); 2028 } 2029 if (b_res == bCancel) 2030 { 2031 memcpy ((void *) raidrec, (void *) &bkp_raidrec, 2032 sizeof (struct vinum_plex)); 2033 } 2034 newtPopWindow(); 2035 newtPopHelpLine (); 1937 } 1938 1939 if (b_res == bCancel) { 1940 memcpy((void *) raidrec, (void *) &bkp_raidrec, 1941 sizeof(struct vinum_plex)); 1942 } 1943 newtPopWindow(); 1944 newtPopHelpLine(); 2036 1945 } 2037 1946 #else … … 2042 1951 * @ingroup restoreGuiVarslist 2043 1952 */ 2044 void 2045 edit_varslist_entry (struct raid_device_record *raidrec, int lino) 1953 void edit_varslist_entry(struct raid_device_record *raidrec, int lino) 2046 1954 { 2047 1955 2048 1956 /** buffers ***********************************************************/ 2049 1957 char header[MAX_STR_LEN]; 2050 1958 char comment[MAX_STR_LEN]; 2051 1959 char sz_out[MAX_STR_LEN]; 2052 1960 2053 assert(raidrec!=0); 2054 assert(lino>=0); 2055 2056 strcpy (sz_out, raidrec->additional_vars.el[lino].value); 2057 sprintf (header, "Edit %s", raidrec->additional_vars.el[lino].label); 2058 sprintf (comment, "Please set %s's value (currently '%s')", 2059 raidrec->additional_vars.el[lino].label, sz_out); 2060 if (popup_and_get_string (header, comment, sz_out, MAX_STR_LEN)) 2061 { 2062 strip_spaces (sz_out); 2063 strcpy (raidrec->additional_vars.el[lino].value, sz_out); 2064 } 1961 assert(raidrec != 0); 1962 assert(lino >= 0); 1963 1964 strcpy(sz_out, raidrec->additional_vars.el[lino].value); 1965 sprintf(header, "Edit %s", raidrec->additional_vars.el[lino].label); 1966 sprintf(comment, "Please set %s's value (currently '%s')", 1967 raidrec->additional_vars.el[lino].label, sz_out); 1968 if (popup_and_get_string(header, comment, sz_out, MAX_STR_LEN)) { 1969 strip_spaces(sz_out); 1970 strcpy(raidrec->additional_vars.el[lino].value, sz_out); 1971 } 2065 1972 } 2066 1973 … … 2077 1984 */ 2078 1985 int 2079 edit_mountlist_in_newt (char*mountlist_fname, struct mountlist_itself *mountlist, 2080 struct raidlist_itself *raidlist) 1986 edit_mountlist_in_newt(char *mountlist_fname, 1987 struct mountlist_itself *mountlist, 1988 struct raidlist_itself *raidlist) 2081 1989 { 2082 1990 2083 1991 /** newt **************************************************************/ 2084 1992 newtComponent myForm; 2085 1993 newtComponent bAdd; 2086 1994 newtComponent bEdit; … … 2097 2005 2098 2006 /** ???? *************************************************************/ 2099 2100 2007 void *curr_choice; 2008 void *keylist[ARBITRARY_MAXIMUM]; 2101 2009 2102 2010 /** int **************************************************************/ 2103 int i= 0;2011 int i = 0; 2104 2012 int currline = 0; 2105 2013 int finished = FALSE; … … 2111 2019 char flaws_str_C[MAX_STR_LEN]; 2112 2020 2113 assert(mountlist!=NULL); 2114 assert(raidlist!=NULL); 2115 2116 strcpy (flaws_str_A, "xxxxxxxxx"); 2117 strcpy (flaws_str_B, "xxxxxxxxx"); 2118 strcpy (flaws_str_C, "xxxxxxxxx"); 2119 if (mountlist->entries > ARBITRARY_MAXIMUM) 2120 { 2121 log_to_screen ("Arbitrary limits suck, man!"); 2122 finish (1); 2123 } 2124 newtPushHelpLine 2125 (" Please edit the mountlist to your satisfaction, then click OK or Cancel."); 2126 i = 4; 2127 bAdd = newtCompactButton (i, 17, " Add "); 2128 bEdit = newtCompactButton (i += 11, 17, " Edit "); 2129 bDelete = newtCompactButton (i += 12, 17, "Delete"); 2130 bReload = newtCompactButton (i += 12, 17, "Reload"); 2131 bCancel = newtCompactButton (i += 12, 17, "Cancel"); 2132 bOK = newtCompactButton (i += 12, 17, " OK "); 2133 sprintf (tmp, "%-24s %-24s %-8s %s", "Device", "Mountpoint", "Format", 2134 "Size (MB)"); 2135 headerMsg = newtLabel (2, 1, tmp); 2136 flawsLabelA = newtLabel (2, 13, flaws_str_A); 2137 flawsLabelB = newtLabel (2, 14, flaws_str_B); 2138 flawsLabelC = newtLabel (2, 15, flaws_str_C); 2139 partitionsListbox = 2140 newtListbox (2, 2, 10, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 2141 redraw_mountlist (mountlist, keylist, partitionsListbox); 2142 newtOpenWindow (1, 3, 77, 18, "Editing mountlist"); 2143 myForm = newtForm (NULL, NULL, 0); 2144 newtFormAddComponents (myForm, headerMsg, partitionsListbox, flawsLabelA, 2145 flawsLabelB, flawsLabelC, bAdd, bEdit, bDelete, 2146 bReload, bCancel, bOK, NULL); 2147 while (!finished) 2148 { 2149 evaluate_mountlist (mountlist, flaws_str_A, flaws_str_B, flaws_str_C); 2150 newtLabelSetText (flawsLabelA, flaws_str_A); 2151 newtLabelSetText (flawsLabelB, flaws_str_B); 2152 newtLabelSetText (flawsLabelC, flaws_str_C); 2153 b_res = newtRunForm (myForm); 2154 if (b_res == bOK) 2155 { 2156 if (!evaluate_mountlist 2157 (mountlist, flaws_str_A, flaws_str_B, flaws_str_C)) 2158 { 2159 finished = 2160 ask_me_yes_or_no 2161 ("Your mountlist might not work. Continue anyway?"); 2162 } 2163 else 2164 { 2165 finished = 2166 ask_me_yes_or_no 2167 ("Are you sure you want to save your mountlist and continue? (No changes will be made to your partition table at this time.)"); 2168 } 2169 } 2170 else if (b_res == bCancel) 2171 { 2172 finished = TRUE; 2173 } 2174 else if (b_res == bReload) 2175 { 2176 if (ask_me_yes_or_no ("Reload original mountlist?")) 2177 { 2021 assert(mountlist != NULL); 2022 assert(raidlist != NULL); 2023 2024 strcpy(flaws_str_A, "xxxxxxxxx"); 2025 strcpy(flaws_str_B, "xxxxxxxxx"); 2026 strcpy(flaws_str_C, "xxxxxxxxx"); 2027 if (mountlist->entries > ARBITRARY_MAXIMUM) { 2028 log_to_screen("Arbitrary limits suck, man!"); 2029 finish(1); 2030 } 2031 newtPushHelpLine 2032 (" Please edit the mountlist to your satisfaction, then click OK or Cancel."); 2033 i = 4; 2034 bAdd = newtCompactButton(i, 17, " Add "); 2035 bEdit = newtCompactButton(i += 11, 17, " Edit "); 2036 bDelete = newtCompactButton(i += 12, 17, "Delete"); 2037 bReload = newtCompactButton(i += 12, 17, "Reload"); 2038 bCancel = newtCompactButton(i += 12, 17, "Cancel"); 2039 bOK = newtCompactButton(i += 12, 17, " OK "); 2040 sprintf(tmp, "%-24s %-24s %-8s %s", "Device", "Mountpoint", "Format", 2041 "Size (MB)"); 2042 headerMsg = newtLabel(2, 1, tmp); 2043 flawsLabelA = newtLabel(2, 13, flaws_str_A); 2044 flawsLabelB = newtLabel(2, 14, flaws_str_B); 2045 flawsLabelC = newtLabel(2, 15, flaws_str_C); 2046 partitionsListbox = 2047 newtListbox(2, 2, 10, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 2048 redraw_mountlist(mountlist, keylist, partitionsListbox); 2049 newtOpenWindow(1, 3, 77, 18, "Editing mountlist"); 2050 myForm = newtForm(NULL, NULL, 0); 2051 newtFormAddComponents(myForm, headerMsg, partitionsListbox, 2052 flawsLabelA, flawsLabelB, flawsLabelC, bAdd, 2053 bEdit, bDelete, bReload, bCancel, bOK, NULL); 2054 while (!finished) { 2055 evaluate_mountlist(mountlist, flaws_str_A, flaws_str_B, 2056 flaws_str_C); 2057 newtLabelSetText(flawsLabelA, flaws_str_A); 2058 newtLabelSetText(flawsLabelB, flaws_str_B); 2059 newtLabelSetText(flawsLabelC, flaws_str_C); 2060 b_res = newtRunForm(myForm); 2061 if (b_res == bOK) { 2062 if (!evaluate_mountlist 2063 (mountlist, flaws_str_A, flaws_str_B, flaws_str_C)) { 2064 finished = 2065 ask_me_yes_or_no 2066 ("Your mountlist might not work. Continue anyway?"); 2067 } else { 2068 finished = 2069 ask_me_yes_or_no 2070 ("Are you sure you want to save your mountlist and continue? (No changes will be made to your partition table at this time.)"); 2071 } 2072 } else if (b_res == bCancel) { 2073 finished = TRUE; 2074 } else if (b_res == bReload) { 2075 if (ask_me_yes_or_no("Reload original mountlist?")) { 2178 2076 /* 2179 2077 This would be really dumb. RAIDTAB_FNAME is #define'd. --- Hugo, 2003/04/24 … … 2184 2082 } 2185 2083 */ 2186 load_mountlist (mountlist, mountlist_fname); 2187 load_raidtab_into_raidlist (raidlist, RAIDTAB_FNAME); 2188 redraw_mountlist (mountlist, keylist, partitionsListbox); 2189 } 2190 } 2191 else 2192 { 2193 curr_choice = newtListboxGetCurrent (partitionsListbox); 2194 for (i = 0; i < mountlist->entries && keylist[i] != curr_choice; 2195 i++); 2196 if (i == mountlist->entries && mountlist->entries > 0) 2197 { 2198 log_to_screen ("I don't know what that button does!"); 2199 } 2200 else 2201 { 2202 currline = i; 2203 if (b_res == bAdd) 2204 { 2205 add_mountlist_entry (mountlist, raidlist, partitionsListbox, 2206 currline, keylist); 2207 } 2208 else if (b_res == bDelete) 2209 { 2210 delete_mountlist_entry (mountlist, raidlist, 2211 partitionsListbox, currline, 2212 keylist); 2213 } 2214 else 2215 { 2216 if (mountlist->entries > 0) 2217 { 2218 edit_mountlist_entry (mountlist, raidlist, 2219 partitionsListbox, currline, 2220 keylist); 2221 } 2222 else 2223 { 2224 popup_and_OK 2225 ("Please add an entry. Then press ENTER to edit it."); 2226 } 2227 } 2228 } 2229 } 2230 } 2231 newtFormDestroy (myForm); 2232 newtPopWindow (); 2233 newtPopHelpLine (); 2234 if (b_res == bOK) 2235 { 2236 log_it("You pushed 'OK'. I shall now continue."); 2237 return (0); 2238 } 2239 else 2240 { 2241 /* popup_and_OK("You pushed 'cancel'. I shall now abort."); */ 2242 return (1); 2243 } 2084 load_mountlist(mountlist, mountlist_fname); 2085 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 2086 redraw_mountlist(mountlist, keylist, partitionsListbox); 2087 } 2088 } else { 2089 curr_choice = newtListboxGetCurrent(partitionsListbox); 2090 for (i = 0; 2091 i < mountlist->entries && keylist[i] != curr_choice; i++); 2092 if (i == mountlist->entries && mountlist->entries > 0) { 2093 log_to_screen("I don't know what that button does!"); 2094 } else { 2095 currline = i; 2096 if (b_res == bAdd) { 2097 add_mountlist_entry(mountlist, raidlist, 2098 partitionsListbox, currline, 2099 keylist); 2100 } else if (b_res == bDelete) { 2101 delete_mountlist_entry(mountlist, raidlist, 2102 partitionsListbox, currline, 2103 keylist); 2104 } else { 2105 if (mountlist->entries > 0) { 2106 edit_mountlist_entry(mountlist, raidlist, 2107 partitionsListbox, currline, 2108 keylist); 2109 } else { 2110 popup_and_OK 2111 ("Please add an entry. Then press ENTER to edit it."); 2112 } 2113 } 2114 } 2115 } 2116 } 2117 newtFormDestroy(myForm); 2118 newtPopWindow(); 2119 newtPopHelpLine(); 2120 if (b_res == bOK) { 2121 log_it("You pushed 'OK'. I shall now continue."); 2122 return (0); 2123 } else { 2124 /* popup_and_OK("You pushed 'cancel'. I shall now abort."); */ 2125 return (1); 2126 } 2244 2127 } 2245 2128 … … 2253 2136 */ 2254 2137 int 2255 edit_mountlist 2256 struct raidlist_itself *raidlist)2257 { 2258 int res=0;2138 edit_mountlist(char *mountlist_fname, struct mountlist_itself *mountlist, 2139 struct raidlist_itself *raidlist) 2140 { 2141 int res = 0; 2259 2142 // char tmp[MAX_STR_LEN]; 2260 2143 2261 iamhere("entering eml"); 2262 2263 if (g_text_mode) 2264 { 2265 fatal_error("Don't call edit_mountlist() in text mode"); 2266 } 2267 else 2268 { 2269 log_it("I'm in GUI mode, so I shall edit mountlist using edit_mountlist()"); 2270 res = edit_mountlist_in_newt(mountlist_fname, mountlist, raidlist); 2271 } 2272 iamhere("leaving eml"); 2273 return(res); 2144 iamhere("entering eml"); 2145 2146 if (g_text_mode) { 2147 fatal_error("Don't call edit_mountlist() in text mode"); 2148 } else { 2149 log_it 2150 ("I'm in GUI mode, so I shall edit mountlist using edit_mountlist()"); 2151 res = edit_mountlist_in_newt(mountlist_fname, mountlist, raidlist); 2152 } 2153 iamhere("leaving eml"); 2154 return (res); 2274 2155 } 2275 2156 … … 2283 2164 * @ingroup restoreGuiVarslist 2284 2165 */ 2285 void 2286 edit_raidrec_additional_vars (struct raid_device_record *raidrec) 2166 void edit_raidrec_additional_vars(struct raid_device_record *raidrec) 2287 2167 { 2288 2168 2289 2169 /** structure *********************************************************/ 2290 2170 struct raid_device_record bkp_raidrec; 2291 2171 2292 2172 /** newt **************************************************************/ 2293 2173 newtComponent myForm; 2294 2174 newtComponent bAdd; 2295 2175 newtComponent bEdit; … … 2302 2182 2303 2183 /** ?? ***************************************************************/ 2304 2184 void *keylist[ARBITRARY_MAXIMUM], *curr_choice; 2305 2185 2306 2186 /** buffers **********************************************************/ 2307 2187 char title_of_window[MAX_STR_LEN]; 2308 2188 2309 2189 /** int **************************************************************/ 2310 2190 int i = 0; 2311 2191 int currline = 0; 2312 2192 2313 2193 2314 assert(raidrec!=NULL); 2315 2316 memcpy ((void *) &bkp_raidrec, (void *) raidrec, 2317 sizeof (struct raid_device_record)); 2318 sprintf (title_of_window, "Additional variables"); 2319 newtPushHelpLine 2320 (" Edit the additional fields to your heart's content, then click OK or Cancel."); 2321 headerMsg = newtLabel (1, 1, "Label Value"); 2322 varsListbox = 2323 newtListbox (1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 2324 i = 1; 2325 bAdd = newtCompactButton (i, 9, " Add "); 2326 bEdit = newtCompactButton (i += 8, 9, " Edit "); 2327 bDelete = newtCompactButton (i += 9, 9, "Delete"); 2328 bOK = newtCompactButton (i += 9, 9, " OK "); 2329 bCancel = newtCompactButton (i += 9, 9, "Cancel"); 2330 newtOpenWindow (17, 7, 46, 10, title_of_window); 2331 myForm = newtForm (NULL, NULL, 0); 2332 newtFormAddComponents (myForm, headerMsg, varsListbox, bAdd, bEdit, bDelete, 2333 bOK, bCancel, NULL); 2334 insert_essential_additionalvars (raidrec); 2335 redraw_varslist (&raidrec->additional_vars, keylist, varsListbox); 2336 for (b_res = NULL; b_res != bOK && b_res != bCancel;) 2337 { 2338 b_res = newtRunForm (myForm); 2339 curr_choice = newtListboxGetCurrent (varsListbox); 2340 for (currline = 0; 2341 currline < raidrec->additional_vars.entries 2342 && keylist[currline] != curr_choice; currline++); 2343 if (currline == raidrec->additional_vars.entries 2344 && raidrec->additional_vars.entries > 0) 2345 { 2346 log_it ("Warning - I don't know what this button does"); 2347 } 2348 if (b_res == bOK) 2349 { /* do nothing */ 2350 } 2351 else if (b_res == bCancel) 2352 { /* do nothing */ 2353 } 2354 else if (b_res == bAdd) 2355 { 2356 add_varslist_entry (raidrec); 2357 } 2358 else if (b_res == bDelete) 2359 { 2360 delete_varslist_entry (raidrec, currline); 2361 } 2362 else 2363 { 2364 edit_varslist_entry (raidrec, currline); 2365 } 2366 redraw_varslist (&raidrec->additional_vars, keylist, varsListbox); 2367 } 2368 remove_essential_additionalvars (raidrec); 2369 newtFormDestroy (myForm); 2370 newtPopWindow (); 2371 newtPopHelpLine (); 2372 if (b_res == bCancel) 2373 { 2374 memcpy ((void *) raidrec, (void *) &bkp_raidrec, 2375 sizeof (struct raid_device_record)); 2376 } 2377 return; 2194 assert(raidrec != NULL); 2195 2196 memcpy((void *) &bkp_raidrec, (void *) raidrec, 2197 sizeof(struct raid_device_record)); 2198 sprintf(title_of_window, "Additional variables"); 2199 newtPushHelpLine 2200 (" Edit the additional fields to your heart's content, then click OK or Cancel."); 2201 headerMsg = newtLabel(1, 1, "Label Value"); 2202 varsListbox = 2203 newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 2204 i = 1; 2205 bAdd = newtCompactButton(i, 9, " Add "); 2206 bEdit = newtCompactButton(i += 8, 9, " Edit "); 2207 bDelete = newtCompactButton(i += 9, 9, "Delete"); 2208 bOK = newtCompactButton(i += 9, 9, " OK "); 2209 bCancel = newtCompactButton(i += 9, 9, "Cancel"); 2210 newtOpenWindow(17, 7, 46, 10, title_of_window); 2211 myForm = newtForm(NULL, NULL, 0); 2212 newtFormAddComponents(myForm, headerMsg, varsListbox, bAdd, bEdit, 2213 bDelete, bOK, bCancel, NULL); 2214 insert_essential_additionalvars(raidrec); 2215 redraw_varslist(&raidrec->additional_vars, keylist, varsListbox); 2216 for (b_res = NULL; b_res != bOK && b_res != bCancel;) { 2217 b_res = newtRunForm(myForm); 2218 curr_choice = newtListboxGetCurrent(varsListbox); 2219 for (currline = 0; 2220 currline < raidrec->additional_vars.entries 2221 && keylist[currline] != curr_choice; currline++); 2222 if (currline == raidrec->additional_vars.entries 2223 && raidrec->additional_vars.entries > 0) { 2224 log_it("Warning - I don't know what this button does"); 2225 } 2226 if (b_res == bOK) { /* do nothing */ 2227 } else if (b_res == bCancel) { /* do nothing */ 2228 } else if (b_res == bAdd) { 2229 add_varslist_entry(raidrec); 2230 } else if (b_res == bDelete) { 2231 delete_varslist_entry(raidrec, currline); 2232 } else { 2233 edit_varslist_entry(raidrec, currline); 2234 } 2235 redraw_varslist(&raidrec->additional_vars, keylist, varsListbox); 2236 } 2237 remove_essential_additionalvars(raidrec); 2238 newtFormDestroy(myForm); 2239 newtPopWindow(); 2240 newtPopHelpLine(); 2241 if (b_res == bCancel) { 2242 memcpy((void *) raidrec, (void *) &bkp_raidrec, 2243 sizeof(struct raid_device_record)); 2244 } 2245 return; 2378 2246 } 2379 2247 #endif … … 2386 2254 * @ingroup restoreGuiDisklist 2387 2255 */ 2388 int 2389 find_next_free_index_in_disklist (struct list_of_disks *disklist) 2256 int find_next_free_index_in_disklist(struct list_of_disks *disklist) 2390 2257 { 2391 2258 2392 2259 /** int ***************************************************************/ 2393 2260 int index = -1; 2394 2261 int pos = 0; 2395 2262 2396 2263 /** bool **************************************************************/ 2397 bool done; 2398 2399 assert(disklist!=NULL); 2400 2401 for (done = FALSE; !done;) 2402 { 2403 for (pos = 0; 2404 pos < disklist->entries && disklist->el[pos].index <= index; 2405 pos++); 2406 if (pos >= disklist->entries) 2407 { 2408 done = TRUE; 2409 } 2410 else 2411 { 2412 index = disklist->el[pos].index; 2413 } 2414 } 2415 return (index + 1); 2264 bool done; 2265 2266 assert(disklist != NULL); 2267 2268 for (done = FALSE; !done;) { 2269 for (pos = 0; 2270 pos < disklist->entries && disklist->el[pos].index <= index; 2271 pos++); 2272 if (pos >= disklist->entries) { 2273 done = TRUE; 2274 } else { 2275 index = disklist->el[pos].index; 2276 } 2277 } 2278 return (index + 1); 2416 2279 } 2417 2280 … … 2426 2289 */ 2427 2290 int 2428 find_raid_device_in_raidlist (struct raidlist_itself *raidlist, char *device) 2291 find_raid_device_in_raidlist(struct raidlist_itself *raidlist, 2292 char *device) 2429 2293 { 2430 2294 2431 2295 /** int ***************************************************************/ 2432 2296 int i = 0; 2433 2297 #ifdef __FreeBSD__ 2434 char vdev[64];2298 char vdev[64]; 2435 2299 #else 2436 2300 // Linux 2437 2301 #endif 2438 2439 assert(raidlist!=NULL);2440 2302 2303 assert(raidlist != NULL); 2304 assert_string_is_neither_NULL_nor_zerolength(device); 2441 2305 2442 2306 #ifdef __FreeBSD__ 2443 for (i = 0; i < raidlist->entries; i++) { 2444 sprintf (vdev, "/dev/vinum/%s", raidlist->el[i].volname); 2445 if (!strcmp (device, vdev)) break; 2446 } 2307 for (i = 0; i < raidlist->entries; i++) { 2308 sprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname); 2309 if (!strcmp(device, vdev)) 2310 break; 2311 } 2447 2312 #else 2448 2313 2449 2450 strcmp (raidlist->el[i].raid_device, device) && i < raidlist->entries; 2451 2314 for (i = 0; 2315 strcmp(raidlist->el[i].raid_device, device) 2316 && i < raidlist->entries; i++); 2452 2317 #endif 2453 if (i == raidlist->entries) 2454 { 2455 return (-1); 2456 } 2457 else 2458 { 2459 return (i); 2460 } 2318 if (i == raidlist->entries) { 2319 return (-1); 2320 } else { 2321 return (i); 2322 } 2461 2323 } 2462 2324 … … 2471 2333 */ 2472 2334 bool 2473 get_isodir_info (char *isodir_device, char *isodir_format, char *isodir_path, bool nuke_me_please) 2335 get_isodir_info(char *isodir_device, char *isodir_format, 2336 char *isodir_path, bool nuke_me_please) 2474 2337 { 2475 2338 2476 2339 /** initialize ********************************************************/ 2477 2340 2478 assert(isodir_device!=NULL); 2479 assert(isodir_format!=NULL); 2480 assert(isodir_path!=NULL); 2481 2482 log_it("%d - AAA - isodir_path = %s", isodir_path); 2483 isodir_format[0] = '\0'; 2484 if (isodir_device[0]=='\0') { strcpy (isodir_device, "/dev/"); } 2485 if (isodir_path[0]=='\0') { strcpy (isodir_path, "/"); } 2486 if (does_file_exist ("/tmp/NFS-SERVER-PATH")) 2487 { 2488 strcpy (isodir_device, last_line_of_file ("/tmp/NFS-SERVER-MOUNT")); 2489 strcpy (isodir_format, "nfs"); 2490 strcpy (isodir_path, last_line_of_file ("/tmp/NFS-SERVER-PATH")); 2491 } 2492 if (nuke_me_please) { return(TRUE); } 2493 2494 if (popup_and_get_string 2495 ("ISO Mode - device", "On what device do the ISO files live?", 2496 isodir_device, MAX_STR_LEN/4)) 2497 { 2498 if (popup_and_get_string 2499 ("ISO Mode - format", 2500 "What is the disk format of the device? (Hit ENTER if you don't know.)", 2501 isodir_format, 16)) 2502 { 2503 if (popup_and_get_string 2504 ("ISO Mode - path", 2505 "At what path on this device can the ISO files be found?", 2506 isodir_path, MAX_STR_LEN/4)) 2507 { 2508 strip_spaces (isodir_device); 2509 strip_spaces (isodir_format); 2510 strip_spaces (isodir_path); 2511 log_it("%d - BBB - isodir_path = %s", isodir_path); 2512 return (TRUE); 2513 } 2514 } 2515 } 2516 return (FALSE); 2341 assert(isodir_device != NULL); 2342 assert(isodir_format != NULL); 2343 assert(isodir_path != NULL); 2344 2345 log_it("%d - AAA - isodir_path = %s", isodir_path); 2346 isodir_format[0] = '\0'; 2347 if (isodir_device[0] == '\0') { 2348 strcpy(isodir_device, "/dev/"); 2349 } 2350 if (isodir_path[0] == '\0') { 2351 strcpy(isodir_path, "/"); 2352 } 2353 if (does_file_exist("/tmp/NFS-SERVER-PATH")) { 2354 strcpy(isodir_device, last_line_of_file("/tmp/NFS-SERVER-MOUNT")); 2355 strcpy(isodir_format, "nfs"); 2356 strcpy(isodir_path, last_line_of_file("/tmp/NFS-SERVER-PATH")); 2357 } 2358 if (nuke_me_please) { 2359 return (TRUE); 2360 } 2361 2362 if (popup_and_get_string 2363 ("ISO Mode - device", "On what device do the ISO files live?", 2364 isodir_device, MAX_STR_LEN / 4)) { 2365 if (popup_and_get_string 2366 ("ISO Mode - format", 2367 "What is the disk format of the device? (Hit ENTER if you don't know.)", 2368 isodir_format, 16)) { 2369 if (popup_and_get_string 2370 ("ISO Mode - path", 2371 "At what path on this device can the ISO files be found?", 2372 isodir_path, MAX_STR_LEN / 4)) { 2373 strip_spaces(isodir_device); 2374 strip_spaces(isodir_format); 2375 strip_spaces(isodir_path); 2376 log_it("%d - BBB - isodir_path = %s", isodir_path); 2377 return (TRUE); 2378 } 2379 } 2380 } 2381 return (FALSE); 2517 2382 } 2518 2383 … … 2527 2392 */ 2528 2393 void 2529 initiate_new_raidlist_entry 2530 struct mountlist_itself *mountlist, int currline,2531 2394 initiate_new_raidlist_entry(struct raidlist_itself *raidlist, 2395 struct mountlist_itself *mountlist, 2396 int currline, char *device) 2532 2397 { 2533 2398 2534 2399 /** structure *********************************************************/ 2535 struct OSSWAP (raid_device_record, vinum_volume) *raidrec;2400 struct OSSWAP (raid_device_record, vinum_volume) * raidrec; 2536 2401 2537 2402 /** int ***************************************************************/ 2538 int pos_in_raidlist = 0; 2539 2540 assert(raidlist!=NULL); 2541 assert(mountlist!=NULL); 2542 assert_string_is_neither_NULL_nor_zerolength(device); 2543 2544 pos_in_raidlist = 2545 find_raid_device_in_raidlist (raidlist, mountlist->el[currline].device); 2546 if (pos_in_raidlist >= 0) 2547 { 2548 fatal_error ("Sorry, that RAID device already exists. Weird."); 2549 } 2550 pos_in_raidlist = raidlist->entries++; 2551 raidrec = &raidlist->el[pos_in_raidlist]; 2552 initialize_raidrec (raidrec); 2553 strcpy (raidrec->OSSWAP (raid_device, volname), OSSWAP (device, basename (device))); 2403 int pos_in_raidlist = 0; 2404 2405 assert(raidlist != NULL); 2406 assert(mountlist != NULL); 2407 assert_string_is_neither_NULL_nor_zerolength(device); 2408 2409 pos_in_raidlist = 2410 find_raid_device_in_raidlist(raidlist, 2411 mountlist->el[currline].device); 2412 if (pos_in_raidlist >= 0) { 2413 fatal_error("Sorry, that RAID device already exists. Weird."); 2414 } 2415 pos_in_raidlist = raidlist->entries++; 2416 raidrec = &raidlist->el[pos_in_raidlist]; 2417 initialize_raidrec(raidrec); 2418 strcpy(raidrec->OSSWAP(raid_device, volname), 2419 OSSWAP(device, basename(device))); 2554 2420 #ifndef __FreeBSD__ 2555 choose_raid_level(raidrec);2556 select_raid_disks(mountlist, raidlist, raidrec, "data",2557 2421 choose_raid_level(raidrec); 2422 select_raid_disks(mountlist, raidlist, raidrec, "data", 2423 &raidrec->data_disks); 2558 2424 #endif 2559 edit_raidlist_entry(mountlist, raidlist, raidrec, currline);2425 edit_raidlist_entry(mountlist, raidlist, raidrec, currline); 2560 2426 } 2561 2427 … … 2567 2433 * @ingroup restoreGuiVarslist 2568 2434 */ 2569 void 2570 insert_essential_additionalvars (struct raid_device_record *raidrec) 2435 void insert_essential_additionalvars(struct raid_device_record *raidrec) 2571 2436 { 2572 2437 2573 2438 /** int **************************************************************/ 2574 2575 2576 assert(raidrec!=NULL);2577 2578 2579 write_variableINT_to_raid_var_line(raidrec, items++,2580 2581 2582 write_variableINT_to_raid_var_line(raidrec, items++, "chunk-size",2583 2584 2439 int items = 0; 2440 2441 assert(raidrec != NULL); 2442 2443 items = raidrec->additional_vars.entries; 2444 write_variableINT_to_raid_var_line(raidrec, items++, 2445 "persistent-superblock", 2446 raidrec->persistent_superblock); 2447 write_variableINT_to_raid_var_line(raidrec, items++, "chunk-size", 2448 raidrec->chunk_size); 2449 raidrec->additional_vars.entries = items; 2585 2450 } 2586 2451 … … 2590 2455 * Dummy function that proves that we can get to the point where Mondo is run. 2591 2456 */ 2592 void 2593 nuke_mode_dummy () 2457 void nuke_mode_dummy() 2594 2458 { 2595 2459 2596 2460 /** newt *************************************************************/ 2597 2461 newtComponent myForm; 2598 2462 newtComponent b1; 2599 2463 newtComponent b2; … … 2602 2466 2603 2467 2604 2605 2606 newtOpenWindow(24, 3, 32, 13, "Nuking");2607 b1 = newtButton(7, 1, "Slowly");2608 b2 = newtButton(7, 5, "Medium");2609 b3 = newtButton(7, 9, "Quickly");2610 myForm = newtForm(NULL, NULL, 0);2611 newtFormAddComponents(myForm, b1, b2, b3, NULL);2612 b_res = newtRunForm(myForm);2613 newtFormDestroy(myForm);2614 newtPopWindow();2615 newtPopHelpLine();2468 newtPushHelpLine 2469 ("This is where I nuke your hard drives. Mhahahahaha. No-one can stop Mojo Jojo!"); 2470 newtOpenWindow(24, 3, 32, 13, "Nuking"); 2471 b1 = newtButton(7, 1, "Slowly"); 2472 b2 = newtButton(7, 5, "Medium"); 2473 b3 = newtButton(7, 9, "Quickly"); 2474 myForm = newtForm(NULL, NULL, 0); 2475 newtFormAddComponents(myForm, b1, b2, b3, NULL); 2476 b_res = newtRunForm(myForm); 2477 newtFormDestroy(myForm); 2478 newtPopWindow(); 2479 newtPopHelpLine(); 2616 2480 } 2617 2481 … … 2626 2490 */ 2627 2491 void 2628 redraw_disklist 2629 2492 redraw_disklist(struct list_of_disks *disklist, 2493 void *keylist[ARBITRARY_MAXIMUM], newtComponent listbox) 2630 2494 { 2631 2495 2632 2496 /** int *************************************************************/ 2633 int i = 0; 2634 2635 assert(disklist!=NULL); 2636 assert(keylist!=NULL); 2637 assert(listbox!=NULL); 2638 2639 newtListboxClear (listbox); 2640 2641 for (i = 0; i < ARBITRARY_MAXIMUM; i++) 2642 { 2643 keylist[i] = (void *) i; 2644 } 2645 for (i = 0; i < disklist->entries; i++) 2646 { 2647 newtListboxAppendEntry (listbox, disklist_entry_to_string (disklist, i), 2648 keylist[i]); 2649 } 2497 int i = 0; 2498 2499 assert(disklist != NULL); 2500 assert(keylist != NULL); 2501 assert(listbox != NULL); 2502 2503 newtListboxClear(listbox); 2504 2505 for (i = 0; i < ARBITRARY_MAXIMUM; i++) { 2506 keylist[i] = (void *) i; 2507 } 2508 for (i = 0; i < disklist->entries; i++) { 2509 newtListboxAppendEntry(listbox, 2510 disklist_entry_to_string(disklist, i), 2511 keylist[i]); 2512 } 2650 2513 } 2651 2514 … … 2659 2522 */ 2660 2523 void 2661 redraw_mountlist 2662 2663 { 2664 2524 redraw_mountlist(struct mountlist_itself *mountlist, 2525 void *keylist[ARBITRARY_MAXIMUM], newtComponent listbox) 2526 { 2527 2665 2528 /** int **************************************************************/ 2666 2667 2668 assert(mountlist!=NULL);2669 assert(keylist!=NULL);2670 assert(listbox!=NULL);2671 2672 newtListboxClear(listbox);2529 int i = 0; 2530 2531 assert(mountlist != NULL); 2532 assert(keylist != NULL); 2533 assert(listbox != NULL); 2534 2535 newtListboxClear(listbox); 2673 2536 // sort_mountlist_by_device (mountlist); 2674 for (i = 0; i < ARBITRARY_MAXIMUM; i++) 2675 { 2676 keylist[i] = (void *) i; 2677 } 2678 for (i = 0; i < mountlist->entries; i++) 2679 { 2680 newtListboxAppendEntry (listbox, 2681 mountlist_entry_to_string (mountlist, i), 2682 keylist[i]); 2683 } 2537 for (i = 0; i < ARBITRARY_MAXIMUM; i++) { 2538 keylist[i] = (void *) i; 2539 } 2540 for (i = 0; i < mountlist->entries; i++) { 2541 newtListboxAppendEntry(listbox, 2542 mountlist_entry_to_string(mountlist, i), 2543 keylist[i]); 2544 } 2684 2545 } 2685 2546 … … 2694 2555 * @ingroup restoreGuiDisklist 2695 2556 */ 2696 void 2697 redraw_unallocpartnslist (struct mountlist_itself 2698 *unallocated_raid_partitions, 2699 void *keylist[ARBITRARY_MAXIMUM], 2700 newtComponent listbox) 2557 void redraw_unallocpartnslist(struct mountlist_itself 2558 *unallocated_raid_partitions, 2559 void *keylist[ARBITRARY_MAXIMUM], 2560 newtComponent listbox) 2701 2561 { 2702 2562 2703 2563 /** int **************************************************************/ 2704 2564 int i = 0; 2705 2565 2706 2566 /** buffers **********************************************************/ 2707 char tmp[MAX_STR_LEN]; 2708 2709 assert(unallocated_raid_partitions!=NULL); 2710 assert(keylist!=NULL); 2711 assert(listbox!=NULL); 2712 2713 newtListboxClear (listbox); 2714 for (i = 0; i < ARBITRARY_MAXIMUM; i++) 2715 { 2716 keylist[i] = (void *) i; 2717 } 2718 for (i = 0; i < unallocated_raid_partitions->entries; i++) 2719 { 2720 sprintf (tmp, "%-22s %8lld", unallocated_raid_partitions->el[i].device, 2721 unallocated_raid_partitions->el[i].size / 1024); 2722 newtListboxAppendEntry (listbox, tmp, keylist[i]); 2723 } 2567 char tmp[MAX_STR_LEN]; 2568 2569 assert(unallocated_raid_partitions != NULL); 2570 assert(keylist != NULL); 2571 assert(listbox != NULL); 2572 2573 newtListboxClear(listbox); 2574 for (i = 0; i < ARBITRARY_MAXIMUM; i++) { 2575 keylist[i] = (void *) i; 2576 } 2577 for (i = 0; i < unallocated_raid_partitions->entries; i++) { 2578 sprintf(tmp, "%-22s %8lld", 2579 unallocated_raid_partitions->el[i].device, 2580 unallocated_raid_partitions->el[i].size / 1024); 2581 newtListboxAppendEntry(listbox, tmp, keylist[i]); 2582 } 2724 2583 } 2725 2584 … … 2733 2592 */ 2734 2593 void 2735 redraw_varslist 2736 2594 redraw_varslist(struct additional_raid_variables *additional_vars, 2595 void *keylist[], newtComponent listbox) 2737 2596 { 2738 2597 /** int *************************************************************/ 2739 int i= 0;2598 int i = 0; 2740 2599 2741 2600 /** buffers *********************************************************/ 2742 char tmp[MAX_STR_LEN]; 2743 2744 assert(additional_vars!=NULL); 2745 assert(keylist!=NULL); 2746 assert(listbox!=NULL); 2747 2748 newtListboxClear (listbox); 2749 2750 for (i = 0; i < ARBITRARY_MAXIMUM; i++) 2751 { 2752 keylist[i] = (void *) i; 2753 } 2754 for (i = 0; i < additional_vars->entries; i++) 2755 { 2756 sprintf (tmp, "%-32s %-8s", additional_vars->el[i].label, 2757 additional_vars->el[i].value); 2758 newtListboxAppendEntry (listbox, tmp, keylist[i]); 2759 } 2601 char tmp[MAX_STR_LEN]; 2602 2603 assert(additional_vars != NULL); 2604 assert(keylist != NULL); 2605 assert(listbox != NULL); 2606 2607 newtListboxClear(listbox); 2608 2609 for (i = 0; i < ARBITRARY_MAXIMUM; i++) { 2610 keylist[i] = (void *) i; 2611 } 2612 for (i = 0; i < additional_vars->entries; i++) { 2613 sprintf(tmp, "%-32s %-8s", additional_vars->el[i].label, 2614 additional_vars->el[i].value); 2615 newtListboxAppendEntry(listbox, tmp, keylist[i]); 2616 } 2760 2617 } 2761 2618 … … 2769 2626 */ 2770 2627 int 2771 read_variableINT_and_remove_from_raidvars (struct OSSWAP (raid_device_record, vinum_volume) *raidrec, 2772 char *label) 2628 read_variableINT_and_remove_from_raidvars(struct 2629 OSSWAP (raid_device_record, 2630 vinum_volume) * raidrec, 2631 char *label) 2773 2632 { 2774 2633 /** int ***************************************************************/ 2775 int i= 0;2634 int i = 0; 2776 2635 int res = 0; 2777 2636 2778 2637 2779 assert(raidrec!=NULL); 2780 assert(label!=NULL); 2781 2782 for (i = 0; 2783 i < raidrec->additional_vars.entries 2784 && strcmp (raidrec->additional_vars.el[i].label, label); i++); 2785 if (i == raidrec->additional_vars.entries) 2786 { 2787 res = -1; 2788 } 2789 else 2790 { 2791 res = atoi (raidrec->additional_vars.el[i].value); 2792 for (i++; i < raidrec->additional_vars.entries; i++) 2793 { 2794 memcpy ((void *) &raidrec->additional_vars.el[i - 1], 2795 (void *) &raidrec->additional_vars.el[i], 2796 sizeof (struct raid_var_line)); 2797 } 2798 raidrec->additional_vars.entries--; 2799 } 2800 return (res); 2638 assert(raidrec != NULL); 2639 assert(label != NULL); 2640 2641 for (i = 0; 2642 i < raidrec->additional_vars.entries 2643 && strcmp(raidrec->additional_vars.el[i].label, label); i++); 2644 if (i == raidrec->additional_vars.entries) { 2645 res = -1; 2646 } else { 2647 res = atoi(raidrec->additional_vars.el[i].value); 2648 for (i++; i < raidrec->additional_vars.entries; i++) { 2649 memcpy((void *) &raidrec->additional_vars.el[i - 1], 2650 (void *) &raidrec->additional_vars.el[i], 2651 sizeof(struct raid_var_line)); 2652 } 2653 raidrec->additional_vars.entries--; 2654 } 2655 return (res); 2801 2656 } 2802 2657 #endif … … 2809 2664 * @ingroup restoreGuiMountlist 2810 2665 */ 2811 void 2812 rejig_partition_name_in_raidlist_if_necessary (struct raidlist_itself 2813 *raidlist,char *old_dev,2814 2666 void rejig_partition_name_in_raidlist_if_necessary(struct raidlist_itself 2667 *raidlist, 2668 char *old_dev, 2669 char *new_dev) 2815 2670 { 2816 2671 /** buffers ********************************************************/ 2817 2672 char tmp[MAX_STR_LEN]; 2818 2673 2819 2674 /** int ************************************************************/ 2820 2675 int pos = 0; 2821 2676 int j = 0; 2822 2677 2823 assert(raidlist!=NULL); 2824 assert_string_is_neither_NULL_nor_zerolength(old_dev); 2825 assert_string_is_neither_NULL_nor_zerolength(new_dev); 2826 2827 pos = which_raid_device_is_using_this_partition (raidlist, old_dev); 2828 if (pos < 0) 2829 { 2830 sprintf (tmp, "No need to rejig %s in raidlist: it's not listed.", 2831 old_dev); 2832 log_it (tmp); 2833 } 2834 else 2835 { 2836 if ((j = 2837 where_in_drivelist_is_drive (&raidlist->OSSWAP (el[pos].data_disks, disks), 2838 old_dev)) >= 0) 2839 { 2840 strcpy (raidlist->OSSWAP (el[pos].data_disks, disks).el[j].device, new_dev); 2841 } 2842 else 2843 if ((j = 2844 where_in_drivelist_is_drive (&raidlist->OSSWAP (el[pos].spare_disks, spares), 2845 old_dev)) >= 0) 2846 { 2847 strcpy (raidlist->OSSWAP (el[pos].spare_disks, spares).el[j].device, new_dev); 2848 } 2678 assert(raidlist != NULL); 2679 assert_string_is_neither_NULL_nor_zerolength(old_dev); 2680 assert_string_is_neither_NULL_nor_zerolength(new_dev); 2681 2682 pos = which_raid_device_is_using_this_partition(raidlist, old_dev); 2683 if (pos < 0) { 2684 sprintf(tmp, "No need to rejig %s in raidlist: it's not listed.", 2685 old_dev); 2686 log_it(tmp); 2687 } else { 2688 if ((j = 2689 where_in_drivelist_is_drive(&raidlist-> 2690 OSSWAP(el[pos].data_disks, disks), 2691 old_dev)) >= 0) { 2692 strcpy(raidlist->OSSWAP(el[pos].data_disks, disks).el[j]. 2693 device, new_dev); 2694 } else 2695 if ((j = 2696 where_in_drivelist_is_drive(&raidlist-> 2697 OSSWAP(el[pos].spare_disks, 2698 spares), 2699 old_dev)) >= 0) { 2700 strcpy(raidlist->OSSWAP(el[pos].spare_disks, spares).el[j]. 2701 device, new_dev); 2702 } 2849 2703 #ifndef __FreeBSD__ 2850 else 2851 if ((j = 2852 where_in_drivelist_is_drive (&raidlist->el[pos].parity_disks, 2853 old_dev)) >= 0) 2854 { 2855 strcpy (raidlist->el[pos].parity_disks.el[j].device, new_dev); 2856 } 2857 else 2858 if ((j = 2859 where_in_drivelist_is_drive (&raidlist->el[pos].failed_disks, 2860 old_dev)) >= 0) 2861 { 2862 strcpy (raidlist->el[pos].failed_disks.el[j].device, new_dev); 2863 } 2704 else if ((j = 2705 where_in_drivelist_is_drive(&raidlist->el[pos]. 2706 parity_disks, 2707 old_dev)) >= 0) { 2708 strcpy(raidlist->el[pos].parity_disks.el[j].device, new_dev); 2709 } else 2710 if ((j = 2711 where_in_drivelist_is_drive(&raidlist->el[pos]. 2712 failed_disks, 2713 old_dev)) >= 0) { 2714 strcpy(raidlist->el[pos].failed_disks.el[j].device, new_dev); 2715 } 2864 2716 #endif 2865 else 2866 { 2867 sprintf (tmp, 2868 "%s is supposed to be listed in this raid dev but it's not...", 2869 old_dev); 2870 log_it (tmp); 2871 } 2872 } 2717 else { 2718 sprintf(tmp, 2719 "%s is supposed to be listed in this raid dev but it's not...", 2720 old_dev); 2721 log_it(tmp); 2722 } 2723 } 2873 2724 } 2874 2725 … … 2881 2732 * @ingroup restoreUtilityVarslist 2882 2733 */ 2883 void 2884 remove_essential_additionalvars (struct raid_device_record *raidrec) 2734 void remove_essential_additionalvars(struct raid_device_record *raidrec) 2885 2735 { 2886 2736 2887 2737 /** int **************************************************************/ 2888 int res = 0; 2889 2890 assert(raidrec!=NULL); 2891 2892 res = 2893 read_variableINT_and_remove_from_raidvars (raidrec, 2894 "persistent-superblock"); 2895 if (res > 0) 2896 { 2897 raidrec->persistent_superblock = res; 2898 } 2899 res = read_variableINT_and_remove_from_raidvars (raidrec, "chunk-size"); 2900 if (res > 0) 2901 { 2902 raidrec->chunk_size = res; 2903 } 2904 res = read_variableINT_and_remove_from_raidvars (raidrec, "block-size"); 2738 int res = 0; 2739 2740 assert(raidrec != NULL); 2741 2742 res = 2743 read_variableINT_and_remove_from_raidvars(raidrec, 2744 "persistent-superblock"); 2745 if (res > 0) { 2746 raidrec->persistent_superblock = res; 2747 } 2748 res = read_variableINT_and_remove_from_raidvars(raidrec, "chunk-size"); 2749 if (res > 0) { 2750 raidrec->chunk_size = res; 2751 } 2752 res = read_variableINT_and_remove_from_raidvars(raidrec, "block-size"); 2905 2753 } 2906 2754 … … 2915 2763 */ 2916 2764 void 2917 select_raid_disks (struct mountlist_itself *mountlist_dontedit, 2918 struct raidlist_itself *raidlist, 2919 struct raid_device_record *raidrec, 2920 char *description_of_list, struct list_of_disks *disklist) 2921 { 2922 void *curr_choice; 2765 select_raid_disks(struct mountlist_itself *mountlist_dontedit, 2766 struct raidlist_itself *raidlist, 2767 struct raid_device_record *raidrec, 2768 char *description_of_list, 2769 struct list_of_disks *disklist) 2770 { 2771 void *curr_choice; 2923 2772 2924 2773 /** ??? ***************************************************************/ 2925 2774 2926 2775 /** structures ********************************************************/ 2927 2928 2929 2930 2776 struct raidlist_itself *bkp_raidlist; 2777 struct raid_device_record *bkp_raidrec; 2778 struct list_of_disks *bkp_disklist; 2779 struct mountlist_itself *unallocated_raid_partitions; 2931 2780 2932 2781 /** newt **************************************************************/ 2933 newtComponent myForm=NULL;2934 newtComponent bAdd=NULL;2935 newtComponent bDelete =NULL;2936 newtComponent bOK =NULL;2937 newtComponent bCancel =NULL;2938 newtComponent b_res =NULL;2939 newtComponent partitionsListbox =NULL;2940 newtComponent headerMsg =NULL;2782 newtComponent myForm = NULL; 2783 newtComponent bAdd = NULL; 2784 newtComponent bDelete = NULL; 2785 newtComponent bOK = NULL; 2786 newtComponent bCancel = NULL; 2787 newtComponent b_res = NULL; 2788 newtComponent partitionsListbox = NULL; 2789 newtComponent headerMsg = NULL; 2941 2790 2942 2791 /** buffers **********************************************************/ 2943 2944 2945 2946 2947 2948 2792 void *keylist[ARBITRARY_MAXIMUM]; 2793 char *tmp; 2794 char *help_text; 2795 char *title_of_window; 2796 char *sz_res; 2797 char *header_text; 2949 2798 2950 2799 /** int **************************************************************/ 2951 int i = 0; 2952 int currline = 0; 2953 2954 assert(mountlist_dontedit!=NULL); 2955 assert(raidlist!=NULL); 2956 assert(raidrec!=NULL); 2957 assert(description_of_list!=NULL); 2958 assert(disklist!=NULL); 2959 2960 iamhere("malloc'ing"); 2961 malloc_string(tmp); 2962 malloc_string(help_text); 2963 malloc_string(title_of_window); 2964 malloc_string(sz_res); 2965 malloc_string(header_text); 2966 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) 2967 { fatal_error("Cannot malloc space for raidrec"); } 2968 if (!(bkp_disklist = malloc(sizeof(struct list_of_disks)))) 2969 { fatal_error("Cannot malloc space for disklist"); } 2970 if (!(bkp_raidlist = malloc(sizeof(struct raidlist_itself)))) 2971 { fatal_error("Cannot malloc space for raidlist"); } 2972 if (!(unallocated_raid_partitions = malloc(sizeof(struct mountlist_itself)))) 2973 { fatal_error("Cannot malloc space for unallocated_raid_partitions"); } 2974 2975 memcpy ((void *) bkp_raidlist, (void *) raidlist, 2976 sizeof (struct raidlist_itself)); 2977 memcpy ((void *) bkp_raidrec, (void *) raidrec, 2978 sizeof (struct raid_device_record)); 2979 memcpy ((void *) bkp_disklist, (void *) disklist, 2980 sizeof (struct list_of_disks)); 2981 2982 iamhere("Post-malloc"); 2983 strcpy (help_text, 2984 " Edit this RAID device's list of partitions. Choose OK or Cancel when done."); 2985 sprintf (header_text, "%-24s %s", "Device", "Index"); 2986 sprintf (title_of_window, "%s contains...", raidrec->raid_device); 2987 newtPushHelpLine (help_text); 2988 for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;) 2989 { 2990 headerMsg = newtLabel (1, 1, header_text); 2991 partitionsListbox = 2992 newtListbox (1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 2993 redraw_disklist (disklist, keylist, partitionsListbox); 2994 i = 1; 2995 bAdd = newtCompactButton (i, 9, " Add "); 2996 bDelete = newtCompactButton (i += 8, 9, "Delete"); 2997 bOK = newtCompactButton (i += 9, 9, " OK "); 2998 bCancel = newtCompactButton (i += 9, 9, "Cancel"); 2999 newtOpenWindow (21, 7, 38, 10, title_of_window); 3000 myForm = newtForm (NULL, NULL, 0); 3001 if (disklist->entries == 0) 3002 { 3003 newtFormAddComponents (myForm, headerMsg, bAdd, bDelete, bOK, 3004 bCancel, NULL); 3005 } 3006 else 3007 { 3008 newtFormAddComponents (myForm, headerMsg, partitionsListbox, bAdd, 3009 bDelete, bOK, bCancel, NULL); 3010 } 3011 b_res = newtRunForm (myForm); 3012 if (b_res == bOK || b_res == bCancel) 3013 { /* do nothing */ 2800 int i = 0; 2801 int currline = 0; 2802 2803 assert(mountlist_dontedit != NULL); 2804 assert(raidlist != NULL); 2805 assert(raidrec != NULL); 2806 assert(description_of_list != NULL); 2807 assert(disklist != NULL); 2808 2809 iamhere("malloc'ing"); 2810 malloc_string(tmp); 2811 malloc_string(help_text); 2812 malloc_string(title_of_window); 2813 malloc_string(sz_res); 2814 malloc_string(header_text); 2815 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) { 2816 fatal_error("Cannot malloc space for raidrec"); 2817 } 2818 if (!(bkp_disklist = malloc(sizeof(struct list_of_disks)))) { 2819 fatal_error("Cannot malloc space for disklist"); 2820 } 2821 if (!(bkp_raidlist = malloc(sizeof(struct raidlist_itself)))) { 2822 fatal_error("Cannot malloc space for raidlist"); 2823 } 2824 if (! 2825 (unallocated_raid_partitions = 2826 malloc(sizeof(struct mountlist_itself)))) { 2827 fatal_error("Cannot malloc space for unallocated_raid_partitions"); 2828 } 2829 2830 memcpy((void *) bkp_raidlist, (void *) raidlist, 2831 sizeof(struct raidlist_itself)); 2832 memcpy((void *) bkp_raidrec, (void *) raidrec, 2833 sizeof(struct raid_device_record)); 2834 memcpy((void *) bkp_disklist, (void *) disklist, 2835 sizeof(struct list_of_disks)); 2836 2837 iamhere("Post-malloc"); 2838 strcpy(help_text, 2839 " Edit this RAID device's list of partitions. Choose OK or Cancel when done."); 2840 sprintf(header_text, "%-24s %s", "Device", "Index"); 2841 sprintf(title_of_window, "%s contains...", raidrec->raid_device); 2842 newtPushHelpLine(help_text); 2843 for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;) { 2844 headerMsg = newtLabel(1, 1, header_text); 2845 partitionsListbox = 2846 newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 2847 redraw_disklist(disklist, keylist, partitionsListbox); 2848 i = 1; 2849 bAdd = newtCompactButton(i, 9, " Add "); 2850 bDelete = newtCompactButton(i += 8, 9, "Delete"); 2851 bOK = newtCompactButton(i += 9, 9, " OK "); 2852 bCancel = newtCompactButton(i += 9, 9, "Cancel"); 2853 newtOpenWindow(21, 7, 38, 10, title_of_window); 2854 myForm = newtForm(NULL, NULL, 0); 2855 if (disklist->entries == 0) { 2856 newtFormAddComponents(myForm, headerMsg, bAdd, bDelete, bOK, 2857 bCancel, NULL); 2858 } else { 2859 newtFormAddComponents(myForm, headerMsg, partitionsListbox, 2860 bAdd, bDelete, bOK, bCancel, NULL); 2861 } 2862 b_res = newtRunForm(myForm); 2863 if (b_res == bOK || b_res == bCancel) { /* do nothing */ 3014 2864 // That's OK. At the end of this subroutine (after this do/while loop), 3015 2865 // we'll throw away the changes if Cancel was pushed. 3016 } 3017 else 3018 { 3019 curr_choice = newtListboxGetCurrent (partitionsListbox); 3020 for (i = 0; i < disklist->entries && keylist[i] != curr_choice; 3021 i++); 3022 if (i == disklist->entries && disklist->entries > 0) 3023 { 3024 log_to_screen ("I don't know what that button does!"); 3025 } 3026 else 3027 { 3028 currline = i; 3029 if (b_res == bAdd) 3030 { 3031 log_it ("Making list of unallocated RAID slices"); 3032 make_list_of_unallocated_raid_partitions 3033 (unallocated_raid_partitions, mountlist_dontedit, 3034 raidlist); 3035 if (unallocated_raid_partitions->entries <= 0) 3036 { 3037 popup_and_OK 3038 ("There are no unallocated partitions marked for RAID."); 3039 } 3040 else 3041 { 3042 log_it 3043 ("Done. The user may add one or more of the above to RAID device"); 3044 add_disklist_entry (disklist, raidrec->raid_device, 3045 unallocated_raid_partitions); 3046 log_it ("I have finished adding a disklist entry."); 3047 redraw_disklist (disklist, keylist, partitionsListbox); 3048 } 3049 } 3050 else if (b_res == bDelete) 3051 { 3052 delete_disklist_entry (disklist, raidrec->raid_device, 3053 currline); 3054 redraw_disklist (disklist, keylist, partitionsListbox); 3055 } 3056 else 3057 { 3058 sprintf (tmp, "%s's index is %d. What should it be?", 3059 raidrec->raid_device, 3060 disklist->el[currline].index); 3061 sprintf (sz_res, "%d", disklist->el[currline].index); 3062 if (popup_and_get_string ("Set index", tmp, sz_res, 10)) 3063 { 3064 disklist->el[currline].index = atoi (sz_res); 3065 } 3066 redraw_disklist (disklist, keylist, partitionsListbox); 3067 } 3068 } 3069 } 3070 newtFormDestroy (myForm); 3071 newtPopWindow (); 3072 } 3073 newtPopHelpLine (); 3074 if (b_res == bCancel) 3075 { 3076 memcpy ((void *) raidlist, (void *) bkp_raidlist, 3077 sizeof (struct raidlist_itself)); 3078 memcpy ((void *) raidrec, (void *) bkp_raidrec, 3079 sizeof (struct raid_device_record)); 3080 memcpy ((void *) disklist, (void *) bkp_disklist, 3081 sizeof (struct list_of_disks)); 3082 } 3083 paranoid_free(tmp); 3084 paranoid_free(help_text); 3085 paranoid_free(title_of_window); 3086 paranoid_free(sz_res); 3087 paranoid_free(header_text); 3088 paranoid_free(bkp_raidrec); 3089 paranoid_free(bkp_disklist); 3090 paranoid_free(bkp_raidlist); 3091 paranoid_free(unallocated_raid_partitions); 2866 } else { 2867 curr_choice = newtListboxGetCurrent(partitionsListbox); 2868 for (i = 0; i < disklist->entries && keylist[i] != curr_choice; 2869 i++); 2870 if (i == disklist->entries && disklist->entries > 0) { 2871 log_to_screen("I don't know what that button does!"); 2872 } else { 2873 currline = i; 2874 if (b_res == bAdd) { 2875 log_it("Making list of unallocated RAID slices"); 2876 make_list_of_unallocated_raid_partitions 2877 (unallocated_raid_partitions, mountlist_dontedit, 2878 raidlist); 2879 if (unallocated_raid_partitions->entries <= 0) { 2880 popup_and_OK 2881 ("There are no unallocated partitions marked for RAID."); 2882 } else { 2883 log_it 2884 ("Done. The user may add one or more of the above to RAID device"); 2885 add_disklist_entry(disklist, raidrec->raid_device, 2886 unallocated_raid_partitions); 2887 log_it("I have finished adding a disklist entry."); 2888 redraw_disklist(disklist, keylist, 2889 partitionsListbox); 2890 } 2891 } else if (b_res == bDelete) { 2892 delete_disklist_entry(disklist, raidrec->raid_device, 2893 currline); 2894 redraw_disklist(disklist, keylist, partitionsListbox); 2895 } else { 2896 sprintf(tmp, "%s's index is %d. What should it be?", 2897 raidrec->raid_device, 2898 disklist->el[currline].index); 2899 sprintf(sz_res, "%d", disklist->el[currline].index); 2900 if (popup_and_get_string("Set index", tmp, sz_res, 10)) { 2901 disklist->el[currline].index = atoi(sz_res); 2902 } 2903 redraw_disklist(disklist, keylist, partitionsListbox); 2904 } 2905 } 2906 } 2907 newtFormDestroy(myForm); 2908 newtPopWindow(); 2909 } 2910 newtPopHelpLine(); 2911 if (b_res == bCancel) { 2912 memcpy((void *) raidlist, (void *) bkp_raidlist, 2913 sizeof(struct raidlist_itself)); 2914 memcpy((void *) raidrec, (void *) bkp_raidrec, 2915 sizeof(struct raid_device_record)); 2916 memcpy((void *) disklist, (void *) bkp_disklist, 2917 sizeof(struct list_of_disks)); 2918 } 2919 paranoid_free(tmp); 2920 paranoid_free(help_text); 2921 paranoid_free(title_of_window); 2922 paranoid_free(sz_res); 2923 paranoid_free(header_text); 2924 paranoid_free(bkp_raidrec); 2925 paranoid_free(bkp_disklist); 2926 paranoid_free(bkp_raidlist); 2927 paranoid_free(unallocated_raid_partitions); 3092 2928 } 3093 2929 #endif … … 3100 2936 * or 'E' (or any other letter) for exit. 3101 2937 */ 3102 char 3103 which_restore_mode () 3104 { 3105 2938 char which_restore_mode() 2939 { 2940 3106 2941 /** char *************************************************************/ 3107 3108 3109 2942 char output = '\0'; 2943 char tmp[MAX_STR_LEN]; 2944 3110 2945 /** newt *************************************************************/ 3111 2946 3112 newtComponent b1; 3113 newtComponent b2; 3114 newtComponent b3; 3115 newtComponent b4; 3116 newtComponent b_res; 3117 newtComponent myForm; 3118 3119 if (g_text_mode) 3120 { 3121 for(output='z'; !strchr("AICE", output); output=tmp[0]) 3122 { 3123 printf("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> "); 3124 fgets(tmp, MAX_STR_LEN-1, stdin); 3125 } 3126 return(output); 3127 } 3128 3129 newtPushHelpLine 3130 (" Do you want to 'nuke' your system, restore interactively, or just compare?"); 3131 newtOpenWindow (24, 3, 32, 17, "How should I restore?"); 3132 b1 = newtButton (7, 1, "Automatically"); 3133 b2 = newtButton (7, 5, "Interactively"); 3134 b3 = newtButton (7, 9, "Compare only!"); 3135 b4 = newtButton (7, 13, "Exit to shell"); 3136 myForm = newtForm (NULL, NULL, 0); 3137 newtFormAddComponents (myForm, b1, b2, b3, b4, NULL); 3138 b_res = newtRunForm (myForm); 3139 newtFormDestroy (myForm); 3140 newtPopWindow (); 3141 if (b_res == b1) 3142 { 3143 output = 'N'; 3144 } 3145 if (b_res == b2) 3146 { 3147 output = 'I'; 3148 } 3149 if (b_res == b3) 3150 { 3151 output = 'C'; 3152 } 3153 if (b_res == b4) 3154 { 3155 output = 'E'; 3156 } 3157 newtPopHelpLine (); 3158 return (output); 3159 } 3160 2947 newtComponent b1; 2948 newtComponent b2; 2949 newtComponent b3; 2950 newtComponent b4; 2951 newtComponent b_res; 2952 newtComponent myForm; 2953 2954 if (g_text_mode) { 2955 for (output = 'z'; !strchr("AICE", output); output = tmp[0]) { 2956 printf 2957 ("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> "); 2958 fgets(tmp, MAX_STR_LEN - 1, stdin); 2959 } 2960 return (output); 2961 } 2962 2963 newtPushHelpLine 2964 (" Do you want to 'nuke' your system, restore interactively, or just compare?"); 2965 newtOpenWindow(24, 3, 32, 17, "How should I restore?"); 2966 b1 = newtButton(7, 1, "Automatically"); 2967 b2 = newtButton(7, 5, "Interactively"); 2968 b3 = newtButton(7, 9, "Compare only!"); 2969 b4 = newtButton(7, 13, "Exit to shell"); 2970 myForm = newtForm(NULL, NULL, 0); 2971 newtFormAddComponents(myForm, b1, b2, b3, b4, NULL); 2972 b_res = newtRunForm(myForm); 2973 newtFormDestroy(myForm); 2974 newtPopWindow(); 2975 if (b_res == b1) { 2976 output = 'N'; 2977 } 2978 if (b_res == b2) { 2979 output = 'I'; 2980 } 2981 if (b_res == b3) { 2982 output = 'C'; 2983 } 2984 if (b_res == b4) { 2985 output = 'E'; 2986 } 2987 newtPopHelpLine(); 2988 return (output); 2989 } -
trunk/mondo/mondo/mondorestore/mondo-rstr-newt.h
r30 r59 5 5 copyright : (C) 2002 by Stan Benoit 6 6 email : troff@nakedsoul.org 7 cvsid : $Id : mondo-rstr-newt.h,v 1.3 2004/06/10 15:29:13 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 37 37 /* external subroutines and global vars */ 38 38 39 extern long get_time (void); 40 extern char *last_line_of_file (char *); 41 extern void center_string (char *, int); 42 extern bool does_file_exist (char *); 43 extern void finish (int); 44 extern long get_phys_size_of_drive (char *); 45 extern bool is_this_device_mounted (char *); 46 extern void strip_spaces (char *); 47 extern void initialize_raidrec (struct raid_device_record *); 48 extern int make_list_of_drives (struct mountlist_itself *, 49 char[ARBITRARY_MAXIMUM][MAX_STR_LEN]); 50 char *number_to_text (int); 51 extern void reload_filelist (struct s_node *); 52 extern void toggle_all_root_dirs_on (struct s_node *); 53 extern void toggle_path_expandability (struct s_node *, char *, bool); 54 extern void toggle_path_selection (struct s_node *, char *, bool); 55 extern void toggle_node_selection (struct s_node *, bool); 56 extern struct s_node *find_node_in_filelist (struct s_node *, char *filename); 57 extern int what_number_cd_is_this (struct s_bkpinfo*); 39 extern long get_time(void); 40 extern char *last_line_of_file(char *); 41 extern void center_string(char *, int); 42 extern bool does_file_exist(char *); 43 extern void finish(int); 44 extern long get_phys_size_of_drive(char *); 45 extern bool is_this_device_mounted(char *); 46 extern void strip_spaces(char *); 47 extern void initialize_raidrec(struct raid_device_record *); 48 extern int make_list_of_drives(struct mountlist_itself *, 49 char[ARBITRARY_MAXIMUM][MAX_STR_LEN]); 50 char *number_to_text(int); 51 extern void reload_filelist(struct s_node *); 52 extern void toggle_all_root_dirs_on(struct s_node *); 53 extern void toggle_path_expandability(struct s_node *, char *, bool); 54 extern void toggle_path_selection(struct s_node *, char *, bool); 55 extern void toggle_node_selection(struct s_node *, bool); 56 extern struct s_node *find_node_in_filelist(struct s_node *, 57 char *filename); 58 extern int what_number_cd_is_this(struct s_bkpinfo *); 58 59 //extern void fatal_error (char *); 59 extern void sort_mountlist_by_device 60 extern int load_mountlist 60 extern void sort_mountlist_by_device(struct mountlist_itself *); 61 extern int load_mountlist(struct mountlist_itself *a, char *b); 61 62 extern bool g_text_mode; 62 63 63 64 64 65 /* hacks */ 65 extern int load_raidtab_into_raidlist 66 extern int load_raidtab_into_raidlist(struct raidlist_itself *a, char *b); 66 67 67 68 68 69 69 70 extern long g_start_time, g_minimum_progress, g_maximum_progress, 70 71 g_current_progress, g_currentY; 71 72 extern bool g_ISO_restore_mode; 72 73 … … 92 93 /* my subroutines */ 93 94 94 void add_disklist_entry (struct list_of_disks *, char *, 95 struct mountlist_itself *); 96 void add_mountlist_entry (struct mountlist_itself *, struct raidlist_itself *, 97 newtComponent, int, void *keylist[]); 98 void add_varslist_entry (struct raid_device_record *); 99 bool ask_me_yes_or_no (char *); 100 bool ask_me_OK_or_cancel (char *); 101 long calculate_raid_device_size (struct mountlist_itself *, 102 struct raidlist_itself *, char *); 103 void choose_raid_level (struct 95 void add_disklist_entry(struct list_of_disks *, char *, 96 struct mountlist_itself *); 97 void add_mountlist_entry(struct mountlist_itself *, 98 struct raidlist_itself *, newtComponent, int, 99 void *keylist[]); 100 void add_varslist_entry(struct raid_device_record *); 101 bool ask_me_yes_or_no(char *); 102 bool ask_me_OK_or_cancel(char *); 103 long calculate_raid_device_size(struct mountlist_itself *, 104 struct raidlist_itself *, char *); 105 void choose_raid_level(struct 104 106 #ifdef __FreeBSD__ 105 vinum_plex107 vinum_plex 106 108 #else 107 raid_device_record109 raid_device_record 108 110 #endif 109 *); 110 void close_evalcall_form (void); 111 void close_progress_form (void); 112 void del_partns_listed_in_disklist (struct mountlist_itself *, 113 struct raidlist_itself *, 114 struct list_of_disks *); 115 void delete_disklist_entry (struct list_of_disks *, char *, int); 116 void delete_mountlist_entry (struct mountlist_itself *, 117 struct raidlist_itself *, newtComponent, int, 118 void *keylist[]); 119 void delete_raidlist_entry (struct mountlist_itself *, 120 struct raidlist_itself *, char *); 121 void delete_varslist_entry (struct raid_device_record *, int); 122 char *disklist_entry_to_string (struct list_of_disks *, int); 123 int edit_filelist (struct s_node *); 124 void edit_mountlist_entry (struct mountlist_itself *, 125 struct raidlist_itself *, newtComponent, int, 126 void *keylist[]); 127 void edit_raidlist_entry (struct mountlist_itself *, struct raidlist_itself *, 128 struct raid_device_record *, int); 129 void edit_varslist_entry (struct raid_device_record *, int); 130 int edit_mountlist_in_newt (char *mountlist_fname, struct mountlist_itself *, struct raidlist_itself *); 131 int edit_mountlist (char *mountlist_fname, struct mountlist_itself *, struct raidlist_itself *); 132 void edit_raidrec_additional_vars (struct raid_device_record *); 133 int evaluate_drive_within_mountlist (struct mountlist_itself *, char *, 134 char *); 135 int evaluate_mountlist (struct mountlist_itself *, char *, char *, char *); 136 int find_device_in_mountlist (struct mountlist_itself *, char *); 137 int find_next_free_index_in_disklist (struct list_of_disks *); 138 int find_raid_device_in_raidlist (struct raidlist_itself *, char *); 139 bool get_isodir_info (char *, char *, char *, bool); 140 void initiate_new_raidlist_entry (struct raidlist_itself *, 141 struct mountlist_itself *, int, char *); 142 void insert_essential_additionalvars (struct raid_device_record *); 143 bool is_this_raid_personality_registered (int); 144 void log_file_end_to_screen (char *, char *); 145 void log_to_screen (const char *fmt, ...); 146 int look_for_duplicate_mountpoints (struct mountlist_itself *, char *); 147 int look_for_weird_formats (struct mountlist_itself *, char *); 148 void make_list_of_unallocated_raid_partitions (struct mountlist_itself *, 149 struct mountlist_itself *, 150 struct raidlist_itself *); 151 char *mountlist_entry_to_string (struct mountlist_itself *, int); 152 void mvaddstr_and_log_it (int, int, char *); 153 void nuke_mode_dummy (); 154 char *number_of_disks_as_string (int, char *); 155 void open_evalcall_form (char *); 156 void open_progress_form (char *, char *, char *, char *, long); 157 void popup_and_OK (char *); 158 bool popup_and_get_string (char *, char *, char *, int); 159 bool popup_with_buttons (char *, char *, char *); 160 void redraw_disklist (struct list_of_disks *, void *keylist[], newtComponent); 161 void redraw_mountlist (struct mountlist_itself *, void *keylist[], 162 newtComponent); 163 void redraw_unallocpartnslist (struct mountlist_itself *, void *keylist[], 164 newtComponent); 165 void redraw_varslist (struct additional_raid_variables *, void *keylist[], 166 newtComponent); 167 int read_variableINT_and_remove_from_raidvars (struct raid_device_record *, 168 char *); 169 void refresh_log_screen (void); 170 void rejig_partition_name_in_raidlist_if_necessary (struct raidlist_itself *, 171 char *, char *); 172 void remove_essential_additionalvars (struct raid_device_record *); 173 void select_raid_disks (struct mountlist_itself *, struct raidlist_itself *, 174 struct raid_device_record *, char *, 175 struct list_of_disks *); 176 void setup_newt_stuff (void); 177 long size_of_specific_device (struct mountlist_itself *, char *); 178 bool spread_flaws_across_three_lines (char *, char *, char *, char *, int); 179 char *turn_raid_level_number_to_string (int); 180 void update_evalcall_form (int); 181 void update_progress_form (char *); 182 void update_progress_form_full (char *, char *, char *); 183 char which_restore_mode (void); 184 void write_variableINT_to_raid_var_line (struct raid_device_record *, int, 185 char *, int); 186 int where_in_drivelist_is_drive (struct list_of_disks *, char *); 111 *); 112 void close_evalcall_form(void); 113 void close_progress_form(void); 114 void del_partns_listed_in_disklist(struct mountlist_itself *, 115 struct raidlist_itself *, 116 struct list_of_disks *); 117 void delete_disklist_entry(struct list_of_disks *, char *, int); 118 void delete_mountlist_entry(struct mountlist_itself *, 119 struct raidlist_itself *, newtComponent, int, 120 void *keylist[]); 121 void delete_raidlist_entry(struct mountlist_itself *, 122 struct raidlist_itself *, char *); 123 void delete_varslist_entry(struct raid_device_record *, int); 124 char *disklist_entry_to_string(struct list_of_disks *, int); 125 int edit_filelist(struct s_node *); 126 void edit_mountlist_entry(struct mountlist_itself *, 127 struct raidlist_itself *, newtComponent, int, 128 void *keylist[]); 129 void edit_raidlist_entry(struct mountlist_itself *, 130 struct raidlist_itself *, 131 struct raid_device_record *, int); 132 void edit_varslist_entry(struct raid_device_record *, int); 133 int edit_mountlist_in_newt(char *mountlist_fname, 134 struct mountlist_itself *, 135 struct raidlist_itself *); 136 int edit_mountlist(char *mountlist_fname, struct mountlist_itself *, 137 struct raidlist_itself *); 138 void edit_raidrec_additional_vars(struct raid_device_record *); 139 int evaluate_drive_within_mountlist(struct mountlist_itself *, char *, 140 char *); 141 int evaluate_mountlist(struct mountlist_itself *, char *, char *, char *); 142 int find_device_in_mountlist(struct mountlist_itself *, char *); 143 int find_next_free_index_in_disklist(struct list_of_disks *); 144 int find_raid_device_in_raidlist(struct raidlist_itself *, char *); 145 bool get_isodir_info(char *, char *, char *, bool); 146 void initiate_new_raidlist_entry(struct raidlist_itself *, 147 struct mountlist_itself *, int, char *); 148 void insert_essential_additionalvars(struct raid_device_record *); 149 bool is_this_raid_personality_registered(int); 150 void log_file_end_to_screen(char *, char *); 151 void log_to_screen(const char *fmt, ...); 152 int look_for_duplicate_mountpoints(struct mountlist_itself *, char *); 153 int look_for_weird_formats(struct mountlist_itself *, char *); 154 void make_list_of_unallocated_raid_partitions(struct mountlist_itself *, 155 struct mountlist_itself *, 156 struct raidlist_itself *); 157 char *mountlist_entry_to_string(struct mountlist_itself *, int); 158 void mvaddstr_and_log_it(int, int, char *); 159 void nuke_mode_dummy(); 160 char *number_of_disks_as_string(int, char *); 161 void open_evalcall_form(char *); 162 void open_progress_form(char *, char *, char *, char *, long); 163 void popup_and_OK(char *); 164 bool popup_and_get_string(char *, char *, char *, int); 165 bool popup_with_buttons(char *, char *, char *); 166 void redraw_disklist(struct list_of_disks *, void *keylist[], 167 newtComponent); 168 void redraw_mountlist(struct mountlist_itself *, void *keylist[], 169 newtComponent); 170 void redraw_unallocpartnslist(struct mountlist_itself *, void *keylist[], 171 newtComponent); 172 void redraw_varslist(struct additional_raid_variables *, void *keylist[], 173 newtComponent); 174 int read_variableINT_and_remove_from_raidvars(struct raid_device_record *, 175 char *); 176 void refresh_log_screen(void); 177 void rejig_partition_name_in_raidlist_if_necessary(struct raidlist_itself 178 *, char *, char *); 179 void remove_essential_additionalvars(struct raid_device_record *); 180 void select_raid_disks(struct mountlist_itself *, struct raidlist_itself *, 181 struct raid_device_record *, char *, 182 struct list_of_disks *); 183 void setup_newt_stuff(void); 184 long size_of_specific_device(struct mountlist_itself *, char *); 185 bool spread_flaws_across_three_lines(char *, char *, char *, char *, int); 186 char *turn_raid_level_number_to_string(int); 187 void update_evalcall_form(int); 188 void update_progress_form(char *); 189 void update_progress_form_full(char *, char *, char *); 190 char which_restore_mode(void); 191 void write_variableINT_to_raid_var_line(struct raid_device_record *, int, 192 char *, int); 193 int where_in_drivelist_is_drive(struct list_of_disks *, char *); 187 194 char *strip_path(char *); 188 195 -
trunk/mondo/mondo/mondorestore/mondo-rstr-tools-EXT.h
r30 r59 4 4 5 5 extern void free_MR_global_filenames(); 6 extern void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *);7 extern bool is_file_in_list(char *, char*, char*);/* needle, haystack, preamble */6 extern void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *); 7 extern bool is_file_in_list(char *, char *, char *); /* needle, haystack, preamble */ 8 8 extern int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please); 9 9 extern void kill_petris(void); 10 extern int modify_rclocal_one_time( char *path);10 extern int modify_rclocal_one_time(char *path); 11 11 extern int mount_cdrom(struct s_bkpinfo *bkpinfo); 12 extern int mount_device(char *,char*,char*,bool);13 extern int mount_all_devices(struct mountlist_itself *, bool);12 extern int mount_device(char *, char *, char *, bool); 13 extern int mount_all_devices(struct mountlist_itself *, bool); 14 14 extern void protect_against_braindead_sysadmins(void); 15 extern int read_cfg_file_into_bkpinfo( char* cfg_file, struct s_bkpinfo *bkpinfo); 15 extern int read_cfg_file_into_bkpinfo(char *cfg_file, 16 struct s_bkpinfo *bkpinfo); 16 17 struct s_node *process_filelist_and_biggielist(struct s_bkpinfo *); 17 extern int backup_crucial_file(char *path_root, char *filename);18 extern int backup_crucial_file(char *path_root, char *filename); 18 19 extern int run_boot_loader(bool); 19 extern int run_grub(bool, char *);20 extern int run_grub(bool, char *); 20 21 extern int run_lilo(bool); 21 22 extern int run_elilo(bool); … … 23 24 extern char *find_my_editor(void); 24 25 25 extern void streamline_changes_file(char *,char*);26 extern void set_signals( int on);26 extern void streamline_changes_file(char *, char *); 27 extern void set_signals(int on); 27 28 extern void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo); 28 29 //extern void setup_signals(int); 29 30 extern void terminate_daemon(int); 30 31 extern void termination_in_progress(int); 31 extern int unmount_all_devices(struct mountlist_itself *);32 extern int unmount_all_devices(struct mountlist_itself *); 32 33 extern int get_cfg_file_from_archive(struct s_bkpinfo *bkpinfo); 33 extern int 34 extract_config_file_from_ramdisk( struct s_bkpinfo *bkpinfo,35 char *ramdisk_fname,36 char *output_cfg_file,37 34 extern int 35 extract_config_file_from_ramdisk(struct s_bkpinfo *bkpinfo, 36 char *ramdisk_fname, 37 char *output_cfg_file, 38 char *output_mountlist_file); 38 39 39 extern void ask_about_these_imagedevs( char *infname, char *outfname);40 extern void ask_about_these_imagedevs(char *infname, char *outfname); 40 41 41 extern void wait_until_software_raids_are_prepped(char*mdstat_file, int wait_for_percentage); 42 extern void wait_until_software_raids_are_prepped(char *mdstat_file, 43 int wait_for_percentage); -
trunk/mondo/mondo/mondorestore/mondo-rstr-tools.c
r30 r59 134 134 135 135 extern bool g_sigpipe_caught; 136 extern bool g_ISO_restore_mode; 136 extern bool g_ISO_restore_mode; /* are we in Iso Mode? */ 137 137 extern bool g_I_have_just_nuked; 138 138 extern char *g_tmpfs_mountpt; … … 140 140 extern char *g_isodir_format; 141 141 extern long g_current_progress, g_maximum_progress; 142 extern char *g_biggielist_txt;// where 'biggielist.txt' is stored, on ramdisk / tempdir;143 144 145 extern char *g_filelist_full;// filelist.full.gz is the list of all regular files146 147 extern char *g_biggielist_pot;// list of big files which _could_ be restored, if the148 149 extern char *g_filelist_imagedevs;// list of devices (e.g. /dev/hda1, /dev/sda5) which150 151 152 extern char *g_imagedevs_restthese;// of the imagedevs listed in FILELIST_IMAGEDEVS,153 154 extern char *g_mondo_cfg_file;// where m*ndo-restore.cfg (the config file) is stored155 extern char *g_mountlist_fname;// where mountlist.txt (the mountlist file) is stored156 extern char *g_mondo_home;// homedir of Mondo; usually /usr/local/share/mondo142 extern char *g_biggielist_txt; // where 'biggielist.txt' is stored, on ramdisk / tempdir; 143 // biggielist.txt is the list of big files stored on the 144 // backup media set in question 145 extern char *g_filelist_full; // filelist.full.gz is the list of all regular files 146 // (excluding big files) stored on the backup media set 147 extern char *g_biggielist_pot; // list of big files which _could_ be restored, if the 148 // user chooses them 149 extern char *g_filelist_imagedevs; // list of devices (e.g. /dev/hda1, /dev/sda5) which 150 // were archived as images, not just /dev entries 151 // ... e.g. NTFS, BeOS partitions 152 extern char *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS, 153 // restore only these 154 extern char *g_mondo_cfg_file; // where m*ndo-restore.cfg (the config file) is stored 155 extern char *g_mountlist_fname; // where mountlist.txt (the mountlist file) is stored 156 extern char *g_mondo_home; // homedir of Mondo; usually /usr/local/share/mondo 157 157 extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; 158 158 … … 170 170 void free_MR_global_filenames() 171 171 { 172 paranoid_free ( g_biggielist_txt);173 paranoid_free ( g_filelist_full);174 paranoid_free ( g_filelist_imagedevs);172 paranoid_free(g_biggielist_txt); 173 paranoid_free(g_filelist_full); 174 paranoid_free(g_filelist_imagedevs); 175 175 // paranoid_free (g_imagedevs_pot ); 176 paranoid_free ( g_imagedevs_restthese);177 paranoid_free ( g_mondo_cfg_file);178 paranoid_free ( g_mountlist_fname);179 paranoid_free ( g_mondo_home);180 paranoid_free ( g_tmpfs_mountpt);181 paranoid_free ( g_isodir_device);182 paranoid_free ( g_isodir_format);176 paranoid_free(g_imagedevs_restthese); 177 paranoid_free(g_mondo_cfg_file); 178 paranoid_free(g_mountlist_fname); 179 paranoid_free(g_mondo_home); 180 paranoid_free(g_tmpfs_mountpt); 181 paranoid_free(g_isodir_device); 182 paranoid_free(g_isodir_format); 183 183 184 184 } … … 193 193 * @ingroup restoreUtilityGroup 194 194 */ 195 void 196 ask_about_these_imagedevs( char *infname, char *outfname ) 197 { 198 FILE *fin; 199 FILE *fout; 195 void ask_about_these_imagedevs(char *infname, char *outfname) 196 { 197 FILE *fin; 198 FILE *fout; 200 199 /************************************************************************ 201 200 * allocate memory regions. test and set -sab 16 feb 2003 * 202 201 ************************************************************************/ 203 char *incoming_ptr; 204 char *question_ptr; 205 206 char incoming[ MAX_STR_LEN ]; 207 char question[ MAX_STR_LEN ]; 208 209 assert_string_is_neither_NULL_nor_zerolength(infname); 210 assert_string_is_neither_NULL_nor_zerolength(outfname); 211 212 incoming_ptr = malloc(sizeof(incoming)); 213 if ( incoming_ptr == NULL ) 214 { 215 fprintf(stderr, "Out of Memory\n"); 216 exit (EXIT_FAILURE); 217 } 218 219 question_ptr = malloc(sizeof(question)); 220 if ( question_ptr == NULL) 221 { 222 fprintf(stderr, "Out of Memory\n"); 223 exit (EXIT_FAILURE); 224 } 225 226 memset (incoming_ptr, '\0', sizeof(incoming)); 227 memset (question_ptr, '\0', sizeof(question)); 228 229 230 231 if (!( fin = fopen( infname,"r") ) ) 232 { 233 fatal_error( "Cannot openin infname" ); 234 } 235 if ( !( fout = fopen( outfname, "w" ) ) ) 236 { 237 fatal_error( "Cannot openin outfname"); 238 } 239 for( fgets( incoming_ptr, MAX_STR_LEN, fin); 240 !feof( fin ); 241 fgets( incoming_ptr, MAX_STR_LEN, fin ) ) 242 { 243 strip_spaces( incoming_ptr ); 244 245 if ( incoming[0] == '\0') 246 { 247 continue; 248 } 249 250 sprintf( question_ptr, 251 "Should I restore the image of %s ?", 252 incoming_ptr ); 253 254 if ( ask_me_yes_or_no( question_ptr ) ) 255 { 256 fprintf( fout, "%s\n", incoming_ptr ); 257 } 258 } 259 202 char *incoming_ptr; 203 char *question_ptr; 204 205 char incoming[MAX_STR_LEN]; 206 char question[MAX_STR_LEN]; 207 208 assert_string_is_neither_NULL_nor_zerolength(infname); 209 assert_string_is_neither_NULL_nor_zerolength(outfname); 210 211 incoming_ptr = malloc(sizeof(incoming)); 212 if (incoming_ptr == NULL) { 213 fprintf(stderr, "Out of Memory\n"); 214 exit(EXIT_FAILURE); 215 } 216 217 question_ptr = malloc(sizeof(question)); 218 if (question_ptr == NULL) { 219 fprintf(stderr, "Out of Memory\n"); 220 exit(EXIT_FAILURE); 221 } 222 223 memset(incoming_ptr, '\0', sizeof(incoming)); 224 memset(question_ptr, '\0', sizeof(question)); 225 226 227 228 if (!(fin = fopen(infname, "r"))) { 229 fatal_error("Cannot openin infname"); 230 } 231 if (!(fout = fopen(outfname, "w"))) { 232 fatal_error("Cannot openin outfname"); 233 } 234 for (fgets(incoming_ptr, MAX_STR_LEN, fin); 235 !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) { 236 strip_spaces(incoming_ptr); 237 238 if (incoming[0] == '\0') { 239 continue; 240 } 241 242 sprintf(question_ptr, 243 "Should I restore the image of %s ?", incoming_ptr); 244 245 if (ask_me_yes_or_no(question_ptr)) { 246 fprintf(fout, "%s\n", incoming_ptr); 247 } 248 } 249 260 250 /*** free memory ***********/ 261 262 263 264 265 266 267 paranoid_fclose( fout);268 paranoid_fclose( fin);251 paranoid_free(incoming_ptr); 252 incoming_ptr = NULL; 253 paranoid_free(question_ptr); 254 question_ptr = NULL; 255 256 257 paranoid_fclose(fout); 258 paranoid_fclose(fin); 269 259 } 270 260 … … 289 279 * @ingroup restoreUtilityGroup 290 280 */ 291 int 292 extract_config_file_from_ramdisk( struct s_bkpinfo *bkpinfo, 293 char *ramdisk_fname, 294 char *output_cfg_file, 295 char *output_mountlist_file) 296 { 297 char *mountpt; 298 char *command; 299 char *orig_fname; 300 int retval=0; 301 302 assert(bkpinfo!=NULL); 303 malloc_string(mountpt); 304 malloc_string(command); 305 malloc_string(orig_fname); 306 assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname); 307 assert_string_is_neither_NULL_nor_zerolength(output_cfg_file); 308 assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file); 309 sprintf( mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir ); 310 sprintf( command, "mkdir -p %s", mountpt ); 311 run_program_and_log_output ( command, FALSE ); 312 sprintf( command, "gzip -dc %s > %s/mindi.rd 2> /dev/null", 313 ramdisk_fname, 314 bkpinfo->tmpdir ); 315 316 run_program_and_log_output( command, FALSE ); 317 sprintf( command, "umount %s", mountpt ); 318 319 run_program_and_log_output( command, FALSE ); 320 321 sprintf( command, "mount -o loop %s/mindi.rd -t ext2 %s", 322 bkpinfo->tmpdir, 323 mountpt ); 324 325 run_program_and_log_output( command, FALSE ); 326 327 sprintf( command, "mkdir -p %s/tmp", bkpinfo->tmpdir); 328 329 run_program_and_log_output( command, FALSE ); 330 331 sprintf( command, 332 "cp -f %s/%s %s", // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg 333 mountpt, g_mondo_cfg_file, 334 output_cfg_file ); 335 run_program_and_log_output(command, FALSE); 336 337 sprintf( orig_fname, "%s/%s", mountpt, g_mountlist_fname ); 338 if (does_file_exist( orig_fname )) 339 { 340 sprintf( command, 341 "cp -f %s %s", 342 orig_fname, output_mountlist_file ); 343 run_program_and_log_output( command, FALSE ); 344 } 345 sprintf( command, "umount %s", mountpt ); 346 run_program_and_log_output( command, FALSE ); 347 if ( !does_file_exist(output_cfg_file) || (!does_file_exist(output_mountlist_file) && does_file_exist(orig_fname)) ) 348 { 349 log_msg(2, "Failed to extract %s and/or %s from ramdisk", 350 output_cfg_file, 351 output_mountlist_file ); 352 retval=1; 353 } 354 else 355 { 356 retval=0; 357 } 358 paranoid_free(mountpt); 359 paranoid_free(command); 360 paranoid_free(orig_fname); 361 return(retval); 281 int 282 extract_config_file_from_ramdisk(struct s_bkpinfo *bkpinfo, 283 char *ramdisk_fname, 284 char *output_cfg_file, 285 char *output_mountlist_file) 286 { 287 char *mountpt; 288 char *command; 289 char *orig_fname; 290 int retval = 0; 291 292 assert(bkpinfo != NULL); 293 malloc_string(mountpt); 294 malloc_string(command); 295 malloc_string(orig_fname); 296 assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname); 297 assert_string_is_neither_NULL_nor_zerolength(output_cfg_file); 298 assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file); 299 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir); 300 sprintf(command, "mkdir -p %s", mountpt); 301 run_program_and_log_output(command, FALSE); 302 sprintf(command, "gzip -dc %s > %s/mindi.rd 2> /dev/null", 303 ramdisk_fname, bkpinfo->tmpdir); 304 305 run_program_and_log_output(command, FALSE); 306 sprintf(command, "umount %s", mountpt); 307 308 run_program_and_log_output(command, FALSE); 309 310 sprintf(command, "mount -o loop %s/mindi.rd -t ext2 %s", 311 bkpinfo->tmpdir, mountpt); 312 313 run_program_and_log_output(command, FALSE); 314 315 sprintf(command, "mkdir -p %s/tmp", bkpinfo->tmpdir); 316 317 run_program_and_log_output(command, FALSE); 318 319 sprintf(command, "cp -f %s/%s %s", // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg 320 mountpt, g_mondo_cfg_file, output_cfg_file); 321 run_program_and_log_output(command, FALSE); 322 323 sprintf(orig_fname, "%s/%s", mountpt, g_mountlist_fname); 324 if (does_file_exist(orig_fname)) { 325 sprintf(command, "cp -f %s %s", orig_fname, output_mountlist_file); 326 run_program_and_log_output(command, FALSE); 327 } 328 sprintf(command, "umount %s", mountpt); 329 run_program_and_log_output(command, FALSE); 330 if (!does_file_exist(output_cfg_file) 331 || (!does_file_exist(output_mountlist_file) 332 && does_file_exist(orig_fname))) { 333 log_msg(2, "Failed to extract %s and/or %s from ramdisk", 334 output_cfg_file, output_mountlist_file); 335 retval = 1; 336 } else { 337 retval = 0; 338 } 339 paranoid_free(mountpt); 340 paranoid_free(command); 341 paranoid_free(orig_fname); 342 return (retval); 362 343 363 344 } … … 372 353 void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *bkpinfo) 373 354 { 374 while(get_cfg_file_from_archive(bkpinfo)) 375 { 376 if (!ask_me_yes_or_no("Failed to find config file/archives. Choose another source?")) 377 { fatal_error("Could not find config file/archives. Aborting."); } 378 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 379 } 355 while (get_cfg_file_from_archive(bkpinfo)) { 356 if (!ask_me_yes_or_no 357 ("Failed to find config file/archives. Choose another source?")) 358 { 359 fatal_error("Could not find config file/archives. Aborting."); 360 } 361 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 362 } 380 363 } 381 364 … … 388 371 * @return TRUE if it's in the list, FALSE if it's not. 389 372 */ 390 bool 391 is_file_in_list(char *f, char *list_fname, char *preamble) 373 bool is_file_in_list(char *f, char *list_fname, char *preamble) 392 374 { 393 375 394 376 /** needs malloc **/ 395 char *command; 396 char *file; 397 char *tmp; 398 int res; 399 400 malloc_string(command); 401 malloc_string(file); 402 malloc_string(tmp); 403 assert_string_is_neither_NULL_nor_zerolength(f); 404 assert_string_is_neither_NULL_nor_zerolength(list_fname); 405 assert(preamble!=NULL); 406 407 if ( strncmp( preamble, f, strlen(preamble ) ) == 0 ) 408 { 409 strcpy( file, f + strlen(preamble) ); 410 } 411 else 412 { 413 strcpy( file, f ); 414 } 415 if ( file[0] == '/' && file[1] == '/') 416 { 417 strcpy( tmp, file ); 418 strcpy( file,tmp + 1 ); 419 } 420 sprintf( tmp,"Checking to see if f=%s, file=%s, is in the list of biggiefiles", f, file); 421 log_msg(2, tmp ); 422 sprintf( command, "cat %s | grep -x \"%s\"", list_fname, file ); 423 res = run_program_and_log_output( command, FALSE); 424 paranoid_free(command); 425 paranoid_free(file); 426 paranoid_free(tmp); 427 if (res) 428 { 429 return(FALSE); 430 } 431 else 432 { 433 return(TRUE); 434 } 435 } 377 char *command; 378 char *file; 379 char *tmp; 380 int res; 381 382 malloc_string(command); 383 malloc_string(file); 384 malloc_string(tmp); 385 assert_string_is_neither_NULL_nor_zerolength(f); 386 assert_string_is_neither_NULL_nor_zerolength(list_fname); 387 assert(preamble != NULL); 388 389 if (strncmp(preamble, f, strlen(preamble)) == 0) { 390 strcpy(file, f + strlen(preamble)); 391 } else { 392 strcpy(file, f); 393 } 394 if (file[0] == '/' && file[1] == '/') { 395 strcpy(tmp, file); 396 strcpy(file, tmp + 1); 397 } 398 sprintf(tmp, 399 "Checking to see if f=%s, file=%s, is in the list of biggiefiles", 400 f, file); 401 log_msg(2, tmp); 402 sprintf(command, "cat %s | grep -x \"%s\"", list_fname, file); 403 res = run_program_and_log_output(command, FALSE); 404 paranoid_free(command); 405 paranoid_free(file); 406 paranoid_free(tmp); 407 if (res) { 408 return (FALSE); 409 } else { 410 return (TRUE); 411 } 412 } 413 436 414 /************************************************************************** 437 415 *END_IS_FILE_IN_LIST * … … 451 429 int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please) 452 430 { 453 char *mount_isodir_command, *tmp, 454 *command; 455 int retval=0, i; 456 bool already_mounted=FALSE; 457 458 assert(bkpinfo!=NULL); 459 malloc_string(mount_isodir_command); 460 malloc_string(tmp); 461 malloc_string(command); 462 g_ISO_restore_mode=TRUE; 463 read_cfg_var( g_mondo_cfg_file, "iso-dev", g_isodir_device); 464 if (bkpinfo->disaster_recovery) 465 { 431 char *mount_isodir_command, *tmp, *command; 432 int retval = 0, i; 433 bool already_mounted = FALSE; 434 435 assert(bkpinfo != NULL); 436 malloc_string(mount_isodir_command); 437 malloc_string(tmp); 438 malloc_string(command); 439 g_ISO_restore_mode = TRUE; 440 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); 441 if (bkpinfo->disaster_recovery) { 466 442 /* Patch Conor Daly 26-june-2004 467 443 * Don't let this clobber an existing bkpinfo->isodir */ 468 469 470 444 if (!bkpinfo->isodir[0]) { 445 strcpy(bkpinfo->isodir, "/tmp/isodir"); 446 } 471 447 /* End patch */ 472 sprintf(command, "mkdir -p %s", bkpinfo->isodir); 473 run_program_and_log_output(command, 5); 474 log_msg(2,"Setting isodir to %s", bkpinfo->isodir); 475 } 476 477 if (!get_isodir_info(g_isodir_device, g_isodir_format, bkpinfo->isodir, nuke_me_please)) {return(1);} 478 paranoid_system("umount "MNT_CDROM" 2> /dev/null"); /* just in case */ 479 480 if (is_this_device_mounted(g_isodir_device)) 481 { 482 log_to_screen("WARNING - isodir is already mounted"); 483 already_mounted=TRUE; 484 } 485 else 486 { 487 sprintf(mount_isodir_command,"mount %s", g_isodir_device); 488 if (strlen(g_isodir_format)>1) 489 { sprintf(mount_isodir_command+strlen(mount_isodir_command)," -t %s", g_isodir_format); } 490 strcat(mount_isodir_command," -o ro "); 491 strcat(mount_isodir_command, bkpinfo->isodir); 492 run_program_and_log_output("df -m", FALSE); 493 sprintf(tmp, "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", mount_isodir_command); 494 log_msg(1,tmp); 495 if (run_program_and_log_output(mount_isodir_command, FALSE)) 496 { popup_and_OK("Cannot mount the device where the ISO files are stored."); return(1); } 497 log_to_screen("I have mounted the device where the ISO files are stored."); 498 } 499 if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { mount_cdrom(bkpinfo); } 500 i=what_number_cd_is_this(bkpinfo); /* has the side-effect of calling mount_cdrom() */ 501 sprintf(tmp,"%s #%d has been mounted via loopback mount", media_descriptor_string(bkpinfo->backup_media_type), i); 502 log_msg(1,tmp); 503 if (i<0) 504 { popup_and_OK("Cannot find ISO images in the directory you specified."); retval=1; } 505 log_msg(2,"%ld: bkpinfo->isodir is now %s", __LINE__, bkpinfo->isodir); 506 paranoid_free(mount_isodir_command); 507 paranoid_free(tmp); 508 paranoid_free(command); 509 return(retval); 448 sprintf(command, "mkdir -p %s", bkpinfo->isodir); 449 run_program_and_log_output(command, 5); 450 log_msg(2, "Setting isodir to %s", bkpinfo->isodir); 451 } 452 453 if (!get_isodir_info 454 (g_isodir_device, g_isodir_format, bkpinfo->isodir, 455 nuke_me_please)) { 456 return (1); 457 } 458 paranoid_system("umount " MNT_CDROM " 2> /dev/null"); /* just in case */ 459 460 if (is_this_device_mounted(g_isodir_device)) { 461 log_to_screen("WARNING - isodir is already mounted"); 462 already_mounted = TRUE; 463 } else { 464 sprintf(mount_isodir_command, "mount %s", g_isodir_device); 465 if (strlen(g_isodir_format) > 1) { 466 sprintf(mount_isodir_command + strlen(mount_isodir_command), 467 " -t %s", g_isodir_format); 468 } 469 strcat(mount_isodir_command, " -o ro "); 470 strcat(mount_isodir_command, bkpinfo->isodir); 471 run_program_and_log_output("df -m", FALSE); 472 sprintf(tmp, 473 "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", 474 mount_isodir_command); 475 log_msg(1, tmp); 476 if (run_program_and_log_output(mount_isodir_command, FALSE)) { 477 popup_and_OK 478 ("Cannot mount the device where the ISO files are stored."); 479 return (1); 480 } 481 log_to_screen 482 ("I have mounted the device where the ISO files are stored."); 483 } 484 if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 485 mount_cdrom(bkpinfo); 486 } 487 i = what_number_cd_is_this(bkpinfo); /* has the side-effect of calling mount_cdrom() */ 488 sprintf(tmp, "%s #%d has been mounted via loopback mount", 489 media_descriptor_string(bkpinfo->backup_media_type), i); 490 log_msg(1, tmp); 491 if (i < 0) { 492 popup_and_OK 493 ("Cannot find ISO images in the directory you specified."); 494 retval = 1; 495 } 496 log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__, 497 bkpinfo->isodir); 498 paranoid_free(mount_isodir_command); 499 paranoid_free(tmp); 500 paranoid_free(command); 501 return (retval); 510 502 } 511 503 … … 516 508 * Kill all Petris processes. 517 509 */ 518 void 519 kill_petris(void) 520 { 521 char *command; 522 malloc_string(command); 523 sprintf( command, "kill `ps wax 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null"); 524 paranoid_system( command ); 525 paranoid_free(command); 526 } 510 void kill_petris(void) 511 { 512 char *command; 513 malloc_string(command); 514 sprintf(command, 515 "kill `ps wax 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null"); 516 paranoid_system(command); 517 paranoid_free(command); 518 } 519 527 520 /************************************************************************** 528 521 *END_KILL_PETRIS * … … 537 530 * @return 0 for success, nonzero for failure. 538 531 */ 539 int 540 modify_rclocal_one_time( char *path ) 532 int modify_rclocal_one_time(char *path) 541 533 { 542 534 /** malloc **/ 543 544 545 546 547 548 549 550 551 552 sprintf( rclocal_fname, "%s/rc.local", path);535 char *rclocal_fname; 536 char *newfile_fname; 537 char *tmp; 538 539 malloc_string(rclocal_fname); 540 malloc_string(newfile_fname); 541 malloc_string(tmp); 542 assert_string_is_neither_NULL_nor_zerolength(path); 543 544 sprintf(rclocal_fname, "%s/rc.local", path); 553 545 554 546 // sprintf(tmp, "chmod 1777 %s/tmp", MNT_RESTORING); 555 547 // run_program_and_log_output( tmp, FALSE ); 556 return( 0 ); /* remove this line to open the floodgates... */ 557 558 if (! does_file_exist( rclocal_fname ) ) 559 { 560 sprintf( rclocal_fname, "%s/rc.d/rc.local", path ); 561 } 562 if (! does_file_exist( rclocal_fname ) ) 563 { 564 paranoid_free(rclocal_fname); 565 paranoid_free(newfile_fname); 566 paranoid_free(tmp); 567 return( 1 ); 568 } 569 sprintf( newfile_fname, "%s/rc.local.mondorescue", path ); 570 sprintf( tmp, "cat %s | grep mondorescue > /dev/null 2> /dev/null",rclocal_fname ); 571 if (system( tmp ) ) 572 { 573 sprintf( tmp,"echo \"[ -e %s ] && %s\n\" >> %s", 574 newfile_fname, 575 newfile_fname, 576 rclocal_fname); 577 578 paranoid_system( tmp ); 579 } 580 sprintf( tmp, "echo -en \"#!/bin/sh\ 548 return (0); /* remove this line to open the floodgates... */ 549 550 if (!does_file_exist(rclocal_fname)) { 551 sprintf(rclocal_fname, "%s/rc.d/rc.local", path); 552 } 553 if (!does_file_exist(rclocal_fname)) { 554 paranoid_free(rclocal_fname); 555 paranoid_free(newfile_fname); 556 paranoid_free(tmp); 557 return (1); 558 } 559 sprintf(newfile_fname, "%s/rc.local.mondorescue", path); 560 sprintf(tmp, "cat %s | grep mondorescue > /dev/null 2> /dev/null", 561 rclocal_fname); 562 if (system(tmp)) { 563 sprintf(tmp, "echo \"[ -e %s ] && %s\n\" >> %s", 564 newfile_fname, newfile_fname, rclocal_fname); 565 566 paranoid_system(tmp); 567 } 568 sprintf(tmp, "echo -en \"#!/bin/sh\ 581 569 \\n\ 582 570 \\n\ … … 587 575 service xfs start\\n\ 588 576 yes | rm -f %s\\n\ 589 \" > %s",rclocal_fname,rclocal_fname,newfile_fname,newfile_fname); 590 sprintf( tmp, "chmod +x \"%s\"", newfile_fname ); 591 run_program_and_log_output( tmp, FALSE ); 592 paranoid_free(rclocal_fname); 593 paranoid_free(newfile_fname); 594 paranoid_free(tmp); 595 return( 0 ); 596 } 577 \" > %s", rclocal_fname, rclocal_fname, newfile_fname, newfile_fname); 578 sprintf(tmp, "chmod +x \"%s\"", newfile_fname); 579 run_program_and_log_output(tmp, FALSE); 580 paranoid_free(rclocal_fname); 581 paranoid_free(newfile_fname); 582 paranoid_free(tmp); 583 return (0); 584 } 585 597 586 /************************************************************************** 598 587 *END_ MODIFY_RCLOCAL_ONE_TIME * … … 609 598 * @return The number of errors encountered (0 for success). 610 599 */ 611 int mount_all_devices(struct mountlist_itself *p_external_copy_of_mountlist, bool writeable) 612 { 613 int retval=0,lino,res; 614 char *tmp, *these_failed, *format; 615 struct mountlist_itself *mountlist; 616 617 malloc_string(tmp); 618 malloc_string(format); 619 malloc_string(these_failed); 620 assert(p_external_copy_of_mountlist!=NULL); 621 mountlist = malloc(sizeof(struct mountlist_itself)); 622 memcpy((void*)mountlist, (void*)p_external_copy_of_mountlist, sizeof(struct mountlist_itself)); 623 sort_mountlist_by_mountpoint(mountlist, 0); 600 int mount_all_devices(struct mountlist_itself 601 *p_external_copy_of_mountlist, bool writeable) 602 { 603 int retval = 0, lino, res; 604 char *tmp, *these_failed, *format; 605 struct mountlist_itself *mountlist; 606 607 malloc_string(tmp); 608 malloc_string(format); 609 malloc_string(these_failed); 610 assert(p_external_copy_of_mountlist != NULL); 611 mountlist = malloc(sizeof(struct mountlist_itself)); 612 memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist, 613 sizeof(struct mountlist_itself)); 614 sort_mountlist_by_mountpoint(mountlist, 0); 624 615 625 616 /** menset **/ 626 these_failed[0] = '\0'; 627 628 mvaddstr_and_log_it( g_currentY, 0, "Mounting devices "); 629 open_progress_form("Mounting devices", 630 "I am now mounting all the drives.", 631 "This should not take long.", 632 "", 633 mountlist->entries); 634 635 for( lino = 0; lino < mountlist->entries; lino++ ) 636 { 637 if ( !strcmp( mountlist->el[lino].device, "/proc" ) ) 638 { 639 log_msg(1, "Again with the /proc - why is this in your mountlist?"); 640 } 641 else if ( is_this_device_mounted( mountlist->el[lino].device ) ) 642 { 643 sprintf( tmp, "%s is already mounted",mountlist->el[lino].device ); 644 log_to_screen( tmp ); 645 } 646 else if ( strcmp( mountlist->el[lino].mountpoint, "none" ) && strcmp( mountlist->el[lino].mountpoint, "lvm" ) && strcmp( mountlist->el[lino].mountpoint,"raid" ) && strcmp(mountlist->el[lino].mountpoint, "image" ) ) 647 { 648 sprintf( tmp, "Mounting %s",mountlist->el[lino].device ); 649 update_progress_form( tmp ); 650 strcpy(format, mountlist->el[lino].format); 651 if (!strcmp(format, "ext3")) { strcpy(format, "ext2"); } 652 res = mount_device( mountlist->el[lino].device, 653 mountlist->el[lino].mountpoint, 654 format, 655 writeable ); 656 retval += res; 657 if ( res ) 658 { 659 strcat( these_failed,mountlist->el[lino].device ); 660 strcat( these_failed, " " ); 661 } 662 } 663 g_current_progress++; 664 } 665 close_progress_form(); 666 run_program_and_log_output( "df -m", TRUE ); 667 if ( retval ) 668 { 669 if (g_partition_table_locked_up > 0) 670 { 671 log_to_screen( 672 "fdisk's ictol() call to refresh its copy of the partition table causes the kernel to"); 673 log_to_screen( 674 "lock up the partition table. You might have to reboot and use Interactive Mode to"); 675 log_to_screen( 676 "format and restore *without* partitioning first. Sorry for the inconvenience."); 677 } 678 sprintf( tmp, "Could not mount devices %s- shall I abort?", these_failed ); 679 if ( !ask_me_yes_or_no( tmp ) ) 680 { 681 retval = 0; 682 log_to_screen( "Continuing, although some devices failed to be mounted" ); 683 mvaddstr_and_log_it( g_currentY++, 74, "Done." ); 684 } 685 else 686 { 687 mvaddstr_and_log_it( g_currentY++, 74, "Failed." ); 688 log_to_screen( "Unable to mount some or all of your partitions." ); 689 } 690 } 691 else 692 { 693 log_to_screen("All partitions were mounted OK."); 694 mvaddstr_and_log_it(g_currentY++,74,"Done."); 695 } 696 run_program_and_log_output("df -m", 3); 697 paranoid_free(mountlist); 698 paranoid_free(tmp); 699 paranoid_free(format); 700 paranoid_free(these_failed); 701 return(retval); 702 } 617 these_failed[0] = '\0'; 618 619 mvaddstr_and_log_it(g_currentY, 0, "Mounting devices "); 620 open_progress_form("Mounting devices", 621 "I am now mounting all the drives.", 622 "This should not take long.", 623 "", mountlist->entries); 624 625 for (lino = 0; lino < mountlist->entries; lino++) { 626 if (!strcmp(mountlist->el[lino].device, "/proc")) { 627 log_msg(1, 628 "Again with the /proc - why is this in your mountlist?"); 629 } else if (is_this_device_mounted(mountlist->el[lino].device)) { 630 sprintf(tmp, "%s is already mounted", 631 mountlist->el[lino].device); 632 log_to_screen(tmp); 633 } else if (strcmp(mountlist->el[lino].mountpoint, "none") 634 && strcmp(mountlist->el[lino].mountpoint, "lvm") 635 && strcmp(mountlist->el[lino].mountpoint, "raid") 636 && strcmp(mountlist->el[lino].mountpoint, "image")) { 637 sprintf(tmp, "Mounting %s", mountlist->el[lino].device); 638 update_progress_form(tmp); 639 strcpy(format, mountlist->el[lino].format); 640 if (!strcmp(format, "ext3")) { 641 strcpy(format, "ext2"); 642 } 643 res = mount_device(mountlist->el[lino].device, 644 mountlist->el[lino].mountpoint, 645 format, writeable); 646 retval += res; 647 if (res) { 648 strcat(these_failed, mountlist->el[lino].device); 649 strcat(these_failed, " "); 650 } 651 } 652 g_current_progress++; 653 } 654 close_progress_form(); 655 run_program_and_log_output("df -m", TRUE); 656 if (retval) { 657 if (g_partition_table_locked_up > 0) { 658 log_to_screen 659 ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to"); 660 log_to_screen 661 ("lock up the partition table. You might have to reboot and use Interactive Mode to"); 662 log_to_screen 663 ("format and restore *without* partitioning first. Sorry for the inconvenience."); 664 } 665 sprintf(tmp, "Could not mount devices %s- shall I abort?", 666 these_failed); 667 if (!ask_me_yes_or_no(tmp)) { 668 retval = 0; 669 log_to_screen 670 ("Continuing, although some devices failed to be mounted"); 671 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 672 } else { 673 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 674 log_to_screen 675 ("Unable to mount some or all of your partitions."); 676 } 677 } else { 678 log_to_screen("All partitions were mounted OK."); 679 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 680 } 681 run_program_and_log_output("df -m", 3); 682 paranoid_free(mountlist); 683 paranoid_free(tmp); 684 paranoid_free(format); 685 paranoid_free(these_failed); 686 return (retval); 687 } 688 703 689 /************************************************************************** 704 690 *END_MOUNT_ALL_DEVICES * … … 717 703 int mount_cdrom(struct s_bkpinfo *bkpinfo) 718 704 { 719 720 int i,res;705 char *mount_cmd; 706 int i, res; 721 707 #ifdef __FreeBSD__ 722 723 708 char mdd[32]; 709 char *mddev = mdd; 724 710 #endif 725 711 726 malloc_string(mount_cmd); 727 assert(bkpinfo!=NULL); 728 729 if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) 730 { 731 log_msg(8, "Tape/udev. Therefore, no need to mount CDROM."); 732 paranoid_free(mount_cmd); 733 return 0; 734 } 735 736 if (!run_program_and_log_output("mount | fgrep " MNT_CDROM, FALSE)) 737 { 738 log_msg(2,"mount_cdrom() - CD already mounted. Fair enough."); 739 paranoid_free(mount_cmd); 740 return(0); 741 } 742 743 if (bkpinfo->backup_media_type == nfs) 744 { 745 log_msg(2,"Mounting for NFS thingy"); 746 log_msg(2, "isodir = %s", bkpinfo->isodir); 747 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) 748 && am_I_in_disaster_recovery_mode()) 749 { 750 strcpy(bkpinfo->isodir, "/tmp/isodir"); 751 log_msg(1, "isodir is being set to %s", bkpinfo->isodir); 752 } 753 712 malloc_string(mount_cmd); 713 assert(bkpinfo != NULL); 714 715 if (bkpinfo->backup_media_type == tape 716 || bkpinfo->backup_media_type == udev) { 717 log_msg(8, "Tape/udev. Therefore, no need to mount CDROM."); 718 paranoid_free(mount_cmd); 719 return 0; 720 } 721 722 if (!run_program_and_log_output("mount | fgrep " MNT_CDROM, FALSE)) { 723 log_msg(2, "mount_cdrom() - CD already mounted. Fair enough."); 724 paranoid_free(mount_cmd); 725 return (0); 726 } 727 728 if (bkpinfo->backup_media_type == nfs) { 729 log_msg(2, "Mounting for NFS thingy"); 730 log_msg(2, "isodir = %s", bkpinfo->isodir); 731 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) 732 && am_I_in_disaster_recovery_mode()) { 733 strcpy(bkpinfo->isodir, "/tmp/isodir"); 734 log_msg(1, "isodir is being set to %s", bkpinfo->isodir); 735 } 754 736 #ifdef __FreeBSD__ 755 sprintf (mount_cmd, "/mnt/isodir/%s/%s/%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir, g_current_media_number); 756 mddev = make_vn (mount_cmd); 757 sprintf (mount_cmd, "mount_cd9660 -r %s "MNT_CDROM, mddev); 737 sprintf(mount_cmd, "/mnt/isodir/%s/%s/%d.iso", bkpinfo->isodir, 738 bkpinfo->nfs_remote_dir, g_current_media_number); 739 mddev = make_vn(mount_cmd); 740 sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev); 758 741 #else 759 sprintf(mount_cmd, "mount %s/%s/%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->nfs_remote_dir, g_current_media_number, MNT_CDROM); 742 sprintf(mount_cmd, "mount %s/%s/%d.iso -t iso9660 -o loop,ro %s", 743 bkpinfo->isodir, bkpinfo->nfs_remote_dir, 744 g_current_media_number, MNT_CDROM); 760 745 #endif 761 746 762 } 763 else 764 765 if (bkpinfo->backup_media_type == iso) 766 { 747 } else 748 if (bkpinfo->backup_media_type == iso) { 767 749 #ifdef __FreeBSD__ 768 sprintf (mount_cmd, "%s/%d.iso", bkpinfo->isodir, g_current_media_number); 769 mddev = make_vn (mount_cmd); 770 sprintf (mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 750 sprintf(mount_cmd, "%s/%d.iso", bkpinfo->isodir, 751 g_current_media_number); 752 mddev = make_vn(mount_cmd); 753 sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 771 754 #else 772 sprintf(mount_cmd, "mount %s/%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, g_current_media_number, MNT_CDROM); 755 sprintf(mount_cmd, "mount %s/%d.iso -t iso9660 -o loop,ro %s", 756 bkpinfo->isodir, g_current_media_number, MNT_CDROM); 773 757 #endif 774 } 775 else if (strstr(bkpinfo->media_device, "/dev/")) 776 758 } else if (strstr(bkpinfo->media_device, "/dev/")) 777 759 #ifdef __FreeBSD__ 778 { sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM); } 760 { 761 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 762 MNT_CDROM); 763 } 779 764 #else 780 { sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM); } 765 { 766 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", 767 bkpinfo->media_device, MNT_CDROM); 768 } 781 769 #endif 782 770 783 else 784 { 785 if (bkpinfo->disaster_recovery && does_file_exist("/tmp/CDROM-LIVES-HERE")) 786 { strcpy(bkpinfo->media_device, last_line_of_file("/tmp/CDROM-LIVES-HERE")); } 787 else 788 { find_cdrom_device( bkpinfo->media_device, TRUE ); } 771 else { 772 if (bkpinfo->disaster_recovery 773 && does_file_exist("/tmp/CDROM-LIVES-HERE")) { 774 strcpy(bkpinfo->media_device, 775 last_line_of_file("/tmp/CDROM-LIVES-HERE")); 776 } else { 777 find_cdrom_device(bkpinfo->media_device, TRUE); 778 } 789 779 790 780 #ifdef __FreeBSD__ 791 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM); 781 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 782 MNT_CDROM); 792 783 #else 793 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM); 784 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", 785 bkpinfo->media_device, MNT_CDROM); 794 786 #endif 795 787 796 } 797 log_msg(2,"(mount_cdrom) --- command = %s", mount_cmd); 798 for(i=0;i<2;i++) 799 { 800 res=run_program_and_log_output(mount_cmd, FALSE); 801 if (!res) 802 { 803 break; 804 } 805 else 806 { 807 log_msg(2,"Failed to mount CD-ROM drive."); 808 sleep(5); 809 run_program_and_log_output( "sync", FALSE ); 810 } 811 } 812 if (res) { log_msg(2,"Failed, despite %d attempts", i); } 813 else { log_msg(2,"Mounted CD-ROM drive OK"); } 814 paranoid_free(mount_cmd); 815 return(res); 788 } 789 log_msg(2, "(mount_cdrom) --- command = %s", mount_cmd); 790 for (i = 0; i < 2; i++) { 791 res = run_program_and_log_output(mount_cmd, FALSE); 792 if (!res) { 793 break; 794 } else { 795 log_msg(2, "Failed to mount CD-ROM drive."); 796 sleep(5); 797 run_program_and_log_output("sync", FALSE); 798 } 799 } 800 if (res) { 801 log_msg(2, "Failed, despite %d attempts", i); 802 } else { 803 log_msg(2, "Mounted CD-ROM drive OK"); 804 } 805 paranoid_free(mount_cmd); 806 return (res); 816 807 } 817 808 … … 833 824 * @return 0 for success, nonzero for failure. 834 825 */ 835 int 836 mount_device( char *device, char *mpt, char *format, bool writeable) 837 { 838 int res = 0; 826 int mount_device(char *device, char *mpt, char *format, bool writeable) 827 { 828 int res = 0; 839 829 840 830 /** malloc **/ 841 char *tmp, *command, *mountdir, *mountpoint, *additional_parameters; 842 843 assert_string_is_neither_NULL_nor_zerolength(device); 844 assert_string_is_neither_NULL_nor_zerolength(mpt); 845 assert(format!=NULL); 846 malloc_string(tmp); 847 malloc_string(command); 848 malloc_string(mountdir); 849 malloc_string(mountpoint); 850 malloc_string(additional_parameters); 851 852 if (!strcmp (mpt, "/1")) 853 { 854 strcpy (mountpoint, "/"); 855 log_msg (3,"Mommm! SME is being a dildo!"); 856 } 857 else 858 { 859 strcpy (mountpoint, mpt); 860 } 861 862 if ( !strcmp(mountpoint,"lvm" ) ) 863 { 864 return( 0 ); 865 } 866 if ( !strcmp(mountpoint,"image" ) ) 867 { 868 return( 0 ); 869 } 870 sprintf( tmp, "Mounting device %s ", device ); 871 log_msg( 1, tmp ); 872 if ( writeable ) 873 { 874 strcpy( additional_parameters, "-o rw"); 875 } 876 else 877 { 878 strcpy( additional_parameters, "-o ro"); 879 } 880 if (find_home_of_exe("setfattr")) 881 { 882 strcat( additional_parameters, ",user_xattr"); 883 } 884 if (find_home_of_exe("setfacl")) 885 { 886 strcat( additional_parameters, ",acl"); 887 } 888 889 if ( !strcmp( mountpoint,"swap" ) ) 890 { 891 sprintf( command, "swapon %s", device ); 892 } 893 else 894 { 895 if ( !strcmp( mountpoint,"/" ) ) 896 { 897 strcpy( mountdir, MNT_RESTORING); 898 } 899 else 900 { 901 sprintf( mountdir, "%s%s", MNT_RESTORING, mountpoint); 902 } 903 sprintf( command, "mkdir -p %s", mountdir ); 904 run_program_and_log_output( command, FALSE ); 905 sprintf( command, "mount -t %s %s %s %s 2>> %s", format, device, additional_parameters, mountdir, MONDO_LOGFILE ); 906 log_msg(2, "command='%s'", command); 907 } 908 res = run_program_and_log_output( command, TRUE ); 909 if ( res && (strstr(command, "xattr") || strstr(command, "acl"))) 910 { 911 log_msg(1, "Re-trying without the fancy extra parameters"); 912 sprintf( command, "mount -t %s %s %s 2>> %s", format, device, mountdir, MONDO_LOGFILE ); 913 res = run_program_and_log_output( command, TRUE ); 914 } 915 if ( res ) 916 { 917 log_msg(1, "Unable to mount device %s (type %s) at %s", device, format, mountdir ); 918 log_msg(1, "command was '%s'", command); 919 if ( !strcmp( mountpoint, "swap" ) ) 920 { 921 log_to_screen( tmp ); 922 } 923 else 924 { 925 log_msg(2, "Retrying w/o the '-t' switch" ); 926 sprintf( command, "mount %s %s 2>> %s", device, mountdir, MONDO_LOGFILE); 927 log_msg(2, "2nd command = '%s'", command); 928 res = run_program_and_log_output( command, TRUE ); 929 if (res == 0 ) 930 { 931 log_msg(1, "That's OK. I called mount w/o a filesystem type and it worked fine in the end." ); 932 } 933 else 934 { 935 log_to_screen( tmp ); 936 } 937 } 938 } 939 if (res && !strcmp( mountpoint, "swap" )) 940 { 941 log_msg(2, "That's ok. It's just a swap partition."); 942 log_msg(2, "Non-fatal error. Returning 0."); 943 res=0; 944 } 945 946 paranoid_free(tmp); 947 paranoid_free(command); 948 paranoid_free(mountdir); 949 paranoid_free(mountpoint); 950 paranoid_free(additional_parameters); 951 952 return( res ); 953 } 831 char *tmp, *command, *mountdir, *mountpoint, *additional_parameters; 832 833 assert_string_is_neither_NULL_nor_zerolength(device); 834 assert_string_is_neither_NULL_nor_zerolength(mpt); 835 assert(format != NULL); 836 malloc_string(tmp); 837 malloc_string(command); 838 malloc_string(mountdir); 839 malloc_string(mountpoint); 840 malloc_string(additional_parameters); 841 842 if (!strcmp(mpt, "/1")) { 843 strcpy(mountpoint, "/"); 844 log_msg(3, "Mommm! SME is being a dildo!"); 845 } else { 846 strcpy(mountpoint, mpt); 847 } 848 849 if (!strcmp(mountpoint, "lvm")) { 850 return (0); 851 } 852 if (!strcmp(mountpoint, "image")) { 853 return (0); 854 } 855 sprintf(tmp, "Mounting device %s ", device); 856 log_msg(1, tmp); 857 if (writeable) { 858 strcpy(additional_parameters, "-o rw"); 859 } else { 860 strcpy(additional_parameters, "-o ro"); 861 } 862 if (find_home_of_exe("setfattr")) { 863 strcat(additional_parameters, ",user_xattr"); 864 } 865 if (find_home_of_exe("setfacl")) { 866 strcat(additional_parameters, ",acl"); 867 } 868 869 if (!strcmp(mountpoint, "swap")) { 870 sprintf(command, "swapon %s", device); 871 } else { 872 if (!strcmp(mountpoint, "/")) { 873 strcpy(mountdir, MNT_RESTORING); 874 } else { 875 sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint); 876 } 877 sprintf(command, "mkdir -p %s", mountdir); 878 run_program_and_log_output(command, FALSE); 879 sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device, 880 additional_parameters, mountdir, MONDO_LOGFILE); 881 log_msg(2, "command='%s'", command); 882 } 883 res = run_program_and_log_output(command, TRUE); 884 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) { 885 log_msg(1, "Re-trying without the fancy extra parameters"); 886 sprintf(command, "mount -t %s %s %s 2>> %s", format, device, 887 mountdir, MONDO_LOGFILE); 888 res = run_program_and_log_output(command, TRUE); 889 } 890 if (res) { 891 log_msg(1, "Unable to mount device %s (type %s) at %s", device, 892 format, mountdir); 893 log_msg(1, "command was '%s'", command); 894 if (!strcmp(mountpoint, "swap")) { 895 log_to_screen(tmp); 896 } else { 897 log_msg(2, "Retrying w/o the '-t' switch"); 898 sprintf(command, "mount %s %s 2>> %s", device, mountdir, 899 MONDO_LOGFILE); 900 log_msg(2, "2nd command = '%s'", command); 901 res = run_program_and_log_output(command, TRUE); 902 if (res == 0) { 903 log_msg(1, 904 "That's OK. I called mount w/o a filesystem type and it worked fine in the end."); 905 } else { 906 log_to_screen(tmp); 907 } 908 } 909 } 910 if (res && !strcmp(mountpoint, "swap")) { 911 log_msg(2, "That's ok. It's just a swap partition."); 912 log_msg(2, "Non-fatal error. Returning 0."); 913 res = 0; 914 } 915 916 paranoid_free(tmp); 917 paranoid_free(command); 918 paranoid_free(mountdir); 919 paranoid_free(mountpoint); 920 paranoid_free(additional_parameters); 921 922 return (res); 923 } 924 954 925 /************************************************************************** 955 926 *END_MOUNT_DEVICE * … … 962 933 * up correctly on the first boot. 963 934 */ 964 void 965 protect_against_braindead_sysadmins() 966 { 967 run_program_and_log_output( "touch " MNT_RESTORING "/var/log/pacct", FALSE ); 968 run_program_and_log_output( "touch " MNT_RESTORING "/var/account/pacct", FALSE ); 969 if (run_program_and_log_output( "ls " MNT_RESTORING" /tmp", FALSE ) ) 970 { 971 run_program_and_log_output( "chmod 1777 " MNT_RESTORING "/tmp", FALSE ); 972 } 973 run_program_and_log_output( "mkdir -p " MNT_RESTORING "/var/run/console", FALSE ); 974 run_program_and_log_output( "chmod 777 " MNT_RESTORING "/dev/null", FALSE ); 975 run_program_and_log_output( "cd " MNT_RESTORING "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir $i/.disabled ; mv -f $i/.DCOP* $i/.MCOP* $i/.*authority $i/.kde/tmp* $i/.kde/socket* $i/.disabled/ ; done", TRUE); 976 run_program_and_log_output( "rm -f " MNT_RESTORING "/var/run/*.pid", TRUE); 977 run_program_and_log_output( "rm -f " MNT_RESTORING "/var/lock/subsys/*", TRUE); 978 } 935 void protect_against_braindead_sysadmins() 936 { 937 run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct", 938 FALSE); 939 run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct", 940 FALSE); 941 if (run_program_and_log_output("ls " MNT_RESTORING " /tmp", FALSE)) { 942 run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp", 943 FALSE); 944 } 945 run_program_and_log_output("mkdir -p " MNT_RESTORING 946 "/var/run/console", FALSE); 947 run_program_and_log_output("chmod 777 " MNT_RESTORING "/dev/null", 948 FALSE); 949 run_program_and_log_output("cd " MNT_RESTORING 950 "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir $i/.disabled ; mv -f $i/.DCOP* $i/.MCOP* $i/.*authority $i/.kde/tmp* $i/.kde/socket* $i/.disabled/ ; done", 951 TRUE); 952 run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid", 953 TRUE); 954 run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*", 955 TRUE); 956 } 957 979 958 /************************************************************************** 980 959 *END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS * … … 991 970 * @return 0 for success, nonzero for failure. 992 971 */ 993 int 994 read_cfg_file_into_bkpinfo( char* cfgf, struct s_bkpinfo *bkpinfo) 972 int read_cfg_file_into_bkpinfo(char *cfgf, struct s_bkpinfo *bkpinfo) 995 973 { 996 974 /** add mallocs **/ 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 975 char *value; 976 char *tmp; 977 char *command; 978 char *iso_mnt; 979 char *iso_path; 980 char *old_isodir; 981 char cfg_file[100]; 982 t_bkptype media_specified_by_user; 983 984 malloc_string(command); 985 malloc_string(iso_mnt); 986 malloc_string(iso_path); 987 malloc_string(old_isodir); 988 malloc_string(value); 989 malloc_string(tmp); 1012 990 // assert_string_is_neither_NULL_nor_zerolength(cfg_file); 1013 assert(bkpinfo!=NULL); 1014 1015 if (!cfgf) 1016 { strcpy(cfg_file, g_mondo_cfg_file); } 1017 else 1018 { strcpy(cfg_file, cfgf); } 1019 1020 media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified 1021 1022 if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) 1023 { 1024 if ( !strcmp(value, "cdstream" ) ) 1025 { 1026 bkpinfo->backup_media_type = cdstream; 1027 } 1028 else if (!strcmp(value, "cdr")) 1029 { 1030 bkpinfo->backup_media_type = cdr; 1031 } 1032 else if (!strcmp(value, "cdrw")) 1033 { 1034 bkpinfo->backup_media_type = cdrw; 1035 } 1036 else if (!strcmp(value, "dvd")) 1037 { 1038 bkpinfo->backup_media_type = dvd; 1039 } 1040 else if (!strcmp(value, "iso")) 1041 { 991 assert(bkpinfo != NULL); 992 993 if (!cfgf) { 994 strcpy(cfg_file, g_mondo_cfg_file); 995 } else { 996 strcpy(cfg_file, cfgf); 997 } 998 999 media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified 1000 1001 if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) { 1002 if (!strcmp(value, "cdstream")) { 1003 bkpinfo->backup_media_type = cdstream; 1004 } else if (!strcmp(value, "cdr")) { 1005 bkpinfo->backup_media_type = cdr; 1006 } else if (!strcmp(value, "cdrw")) { 1007 bkpinfo->backup_media_type = cdrw; 1008 } else if (!strcmp(value, "dvd")) { 1009 bkpinfo->backup_media_type = dvd; 1010 } else if (!strcmp(value, "iso")) { 1042 1011 /* 1043 1012 if (am_I_in_disaster_recovery_mode() … … 1047 1016 1048 1017 // Patch by Conor Daly - 2004/07/12 1049 1050 if (am_I_in_disaster_recovery_mode()) 1051 {1052 /* Check to see if CD is already mounted before mounting it... */ 1053 if (!is_this_device_mounted("/dev/cdrom")) 1054 {1055 log_msg(2, "NB: CDROM device not mounted, mounting..."); 1056 run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1);1057 1058 if( does_file_exist(MNT_CDROM"/archives/filelist.0"))1018 bkpinfo->backup_media_type = iso; 1019 if (am_I_in_disaster_recovery_mode()) { 1020 /* Check to see if CD is already mounted before mounting it... */ 1021 if (!is_this_device_mounted("/dev/cdrom")) { 1022 log_msg(2, 1023 "NB: CDROM device not mounted, mounting..."); 1024 run_program_and_log_output("mount /dev/cdrom " 1025 MNT_CDROM, 1); 1026 } 1027 if (does_file_exist(MNT_CDROM "/archives/filelist.0")) 1059 1028 // End patch 1060 { 1061 bkpinfo->backup_media_type = cdr; 1062 run_program_and_log_output("umount "MNT_CDROM, 1); 1063 log_it("Re-jigging configuration AGAIN. CD-R, not ISO."); 1064 } 1065 else 1066 { 1067 bkpinfo->backup_media_type = iso; 1068 } 1069 } 1070 } 1071 else if (!strcmp(value, "nfs")) 1072 { 1073 bkpinfo->backup_media_type = nfs; 1074 } 1075 else if (!strcmp(value, "tape")) 1076 { 1077 bkpinfo->backup_media_type = tape; 1078 } 1079 else if (!strcmp(value, "udev")) 1080 { 1081 bkpinfo->backup_media_type = udev; 1082 } 1083 else 1084 { 1085 fatal_error("UNKNOWN bkp-media-type"); 1086 } 1087 } 1088 else 1089 { 1090 fatal_error("backup-media-type not specified!"); 1091 } 1092 if (bkpinfo->disaster_recovery) 1093 { 1094 if (bkpinfo->backup_media_type == cdstream) 1095 { 1096 sprintf(bkpinfo->media_device, "/dev/cdrom"); 1029 { 1030 bkpinfo->backup_media_type = cdr; 1031 run_program_and_log_output("umount " MNT_CDROM, 1); 1032 log_it 1033 ("Re-jigging configuration AGAIN. CD-R, not ISO."); 1034 } else { 1035 bkpinfo->backup_media_type = iso; 1036 } 1037 } 1038 } else if (!strcmp(value, "nfs")) { 1039 bkpinfo->backup_media_type = nfs; 1040 } else if (!strcmp(value, "tape")) { 1041 bkpinfo->backup_media_type = tape; 1042 } else if (!strcmp(value, "udev")) { 1043 bkpinfo->backup_media_type = udev; 1044 } else { 1045 fatal_error("UNKNOWN bkp-media-type"); 1046 } 1047 } else { 1048 fatal_error("backup-media-type not specified!"); 1049 } 1050 if (bkpinfo->disaster_recovery) { 1051 if (bkpinfo->backup_media_type == cdstream) { 1052 sprintf(bkpinfo->media_device, "/dev/cdrom"); 1097 1053 // bkpinfo->media_size[0] = -1; 1098 bkpinfo->media_size[0] = 1999*1024; 1099 bkpinfo->media_size[1] = 650; /* good guess */ 1100 } 1101 else if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) 1102 { 1103 if (read_cfg_var(cfg_file, "media-dev", value)) { fatal_error("Cannot get tape device name from cfg file"); } 1104 strcpy(bkpinfo->media_device, value); 1105 read_cfg_var(cfg_file, "media-size", value); 1106 bkpinfo->media_size[1] = atol(value); 1107 sprintf(tmp,"Backup medium is TAPE --- dev=%s",bkpinfo->media_device); 1108 log_msg(2, tmp); 1109 } 1110 else 1111 { 1112 strcpy(bkpinfo->media_device,"/dev/cdrom"); /* we don't really need this var */ 1113 bkpinfo->media_size[0]= 1999*1024; /* 650, probably, but we don't need this var anyway */ 1114 bkpinfo->media_size[1]=1999*1024; /* 650, probably, but we don't need this var anyway */ 1115 log_msg(2, "Backup medium is CD-R[W]"); 1116 } 1117 } 1118 else 1119 { 1120 log_msg(2, "Not in Disaster Recovery Mode. No need to derive device name from config file."); 1121 } 1122 1123 read_cfg_var(cfg_file, "use-star", value); 1124 if (strstr(value,"yes")) 1125 { 1126 bkpinfo->use_star = TRUE; 1127 log_msg(1, "Goody! ... bkpinfo->use_star is now true."); 1128 } 1129 1130 if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) 1131 { 1132 bkpinfo->internal_tape_block_size = atol(value); 1133 log_msg(1, "Internal tape block size has been custom-set to %ld", bkpinfo->internal_tape_block_size); 1134 } 1135 else 1136 { 1137 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 1138 log_msg(1, "Internal tape block size = default (%ld)", DEFAULT_INTERNAL_TAPE_BLOCK_SIZE); 1139 } 1140 1141 read_cfg_var(cfg_file, "use-lzo", value); 1142 if (strstr(value,"yes")) 1143 { 1144 bkpinfo->use_lzo = TRUE; 1145 strcpy(bkpinfo->zip_exe, "lzop"); 1146 strcpy(bkpinfo->zip_suffix, "lzo"); 1147 } 1148 else 1149 { 1150 read_cfg_var(cfg_file, "use-comp", value); 1151 if (strstr(value,"yes")) 1152 { 1153 bkpinfo->use_lzo = FALSE; 1154 strcpy(bkpinfo->zip_exe, "bzip2"); 1155 strcpy(bkpinfo->zip_suffix, "bz2"); 1156 } 1157 else 1158 { 1159 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0'; 1160 } 1161 } 1162 1163 value[0] = '\0'; 1164 read_cfg_var( cfg_file, "differential", value); 1165 if (!strcmp(value, "yes") || !strcmp(value, "1")) 1166 { 1167 bkpinfo->differential = TRUE; 1168 } 1169 log_msg(2, "differential var = '%s'", value); 1170 if (bkpinfo->differential) 1171 { 1172 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP" ); 1173 } 1174 else 1175 { 1176 log_msg(2, "This is a regular (full) backup"); 1177 } 1178 1179 read_cfg_var( g_mondo_cfg_file, "please-dont-eject", tmp); 1180 if (tmp[0] || strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "donteject")) 1181 { bkpinfo->please_dont_eject = TRUE; log_msg(2, "Ok, I shan't eject when restoring! Groovy."); } 1182 1183 if (bkpinfo->backup_media_type == nfs) 1184 { 1185 if (!cfgf) 1186 { 1187 log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount); 1188 log_msg(2, "nfs_remote_dir remains %s", bkpinfo->nfs_remote_dir); 1189 log_msg(2, "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place"); 1190 } 1191 else 1192 { 1193 read_cfg_var(g_mondo_cfg_file, "nfs-server-mount", bkpinfo->nfs_mount); 1194 read_cfg_var(g_mondo_cfg_file, "nfs-server-path", bkpinfo->nfs_remote_dir); 1195 log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount); 1196 log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir); 1197 } 1198 } 1199 else if (bkpinfo->backup_media_type == iso) 1200 { 1201 /* Patch by Conor Daly 23-june-2004 1202 * to correctly mount iso-dev and set a sensible 1203 * isodir in disaster recovery mode 1204 */ 1205 strcpy (old_isodir, bkpinfo->isodir); 1206 read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt); 1207 read_cfg_var(g_mondo_cfg_file, "isodir", iso_path); 1208 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1209 if (!bkpinfo->isodir[0]) { 1210 strcpy (bkpinfo->isodir, old_isodir); 1211 } 1212 if (!bkpinfo->disaster_recovery) 1213 { 1214 if (strcmp(old_isodir, bkpinfo->isodir)) { 1215 log_it("user nominated isodir differs from archive, keeping user's choice: %s %s\n", old_isodir, bkpinfo->isodir); 1216 strcpy (bkpinfo->isodir, old_isodir); 1217 } 1218 } 1219 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); 1220 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device); 1221 if (bkpinfo->disaster_recovery) { 1222 if (is_this_device_mounted(g_isodir_device)) 1223 { log_msg(2, "NB: isodir is already mounted"); 1224 /* Find out where it's mounted */ 1225 sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", g_isodir_device); 1226 log_it("command = %s", command); 1227 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 1228 sprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command)); 1229 } 1230 else 1231 { 1232 sprintf(iso_mnt, "/tmp/isodir"); 1233 sprintf(tmp, "mkdir -p %s", iso_mnt); 1234 run_program_and_log_output(tmp, 5); 1235 sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt); 1236 if (run_program_and_log_output(tmp, 3)) 1237 { 1238 log_msg(1, "Unable to mount isodir. Perhaps this is really a CD backup?"); 1239 bkpinfo->backup_media_type = cdr; 1240 strcpy(bkpinfo->media_device,"/dev/cdrom"); /* superfluous */ 1241 bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0'; 1242 if ( mount_cdrom( bkpinfo ) ) 1243 { 1244 fatal_error( "Unable to mount isodir. Failed to mount CD-ROM as well."); 1245 } 1246 else 1247 { 1248 log_msg(1, "You backed up to disk, then burned some CDs. Naughty monkey!" ); 1249 } 1250 } 1251 } 1252 /* bkpinfo->isodir should now be the true path to 1.iso etc... */ 1253 if (bkpinfo->backup_media_type == iso) 1254 { 1255 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1256 } 1257 } 1258 } 1259 1260 if (media_specified_by_user != none) 1261 { 1262 if (g_restoring_live_from_cd) 1263 { 1264 if (bkpinfo->backup_media_type != media_specified_by_user) 1265 { 1266 log_msg(2, "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)"); 1267 interactively_obtain_media_parameters_from_user( bkpinfo, FALSE); 1268 media_specified_by_user = bkpinfo->backup_media_type; 1269 get_cfg_file_from_archive(bkpinfo); 1054 bkpinfo->media_size[0] = 1999 * 1024; 1055 bkpinfo->media_size[1] = 650; /* good guess */ 1056 } else if (bkpinfo->backup_media_type == tape 1057 || bkpinfo->backup_media_type == udev) { 1058 if (read_cfg_var(cfg_file, "media-dev", value)) { 1059 fatal_error("Cannot get tape device name from cfg file"); 1060 } 1061 strcpy(bkpinfo->media_device, value); 1062 read_cfg_var(cfg_file, "media-size", value); 1063 bkpinfo->media_size[1] = atol(value); 1064 sprintf(tmp, "Backup medium is TAPE --- dev=%s", 1065 bkpinfo->media_device); 1066 log_msg(2, tmp); 1067 } else { 1068 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* we don't really need this var */ 1069 bkpinfo->media_size[0] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */ 1070 bkpinfo->media_size[1] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */ 1071 log_msg(2, "Backup medium is CD-R[W]"); 1072 } 1073 } else { 1074 log_msg(2, 1075 "Not in Disaster Recovery Mode. No need to derive device name from config file."); 1076 } 1077 1078 read_cfg_var(cfg_file, "use-star", value); 1079 if (strstr(value, "yes")) { 1080 bkpinfo->use_star = TRUE; 1081 log_msg(1, "Goody! ... bkpinfo->use_star is now true."); 1082 } 1083 1084 if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) { 1085 bkpinfo->internal_tape_block_size = atol(value); 1086 log_msg(1, "Internal tape block size has been custom-set to %ld", 1087 bkpinfo->internal_tape_block_size); 1088 } else { 1089 bkpinfo->internal_tape_block_size = 1090 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 1091 log_msg(1, "Internal tape block size = default (%ld)", 1092 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE); 1093 } 1094 1095 read_cfg_var(cfg_file, "use-lzo", value); 1096 if (strstr(value, "yes")) { 1097 bkpinfo->use_lzo = TRUE; 1098 strcpy(bkpinfo->zip_exe, "lzop"); 1099 strcpy(bkpinfo->zip_suffix, "lzo"); 1100 } else { 1101 read_cfg_var(cfg_file, "use-comp", value); 1102 if (strstr(value, "yes")) { 1103 bkpinfo->use_lzo = FALSE; 1104 strcpy(bkpinfo->zip_exe, "bzip2"); 1105 strcpy(bkpinfo->zip_suffix, "bz2"); 1106 } else { 1107 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0'; 1108 } 1109 } 1110 1111 value[0] = '\0'; 1112 read_cfg_var(cfg_file, "differential", value); 1113 if (!strcmp(value, "yes") || !strcmp(value, "1")) { 1114 bkpinfo->differential = TRUE; 1115 } 1116 log_msg(2, "differential var = '%s'", value); 1117 if (bkpinfo->differential) { 1118 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP"); 1119 } else { 1120 log_msg(2, "This is a regular (full) backup"); 1121 } 1122 1123 read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp); 1124 if (tmp[0] 1125 || 1126 strstr(call_program_and_get_last_line_of_output 1127 ("cat /proc/cmdline"), "donteject")) { 1128 bkpinfo->please_dont_eject = TRUE; 1129 log_msg(2, "Ok, I shan't eject when restoring! Groovy."); 1130 } 1131 1132 if (bkpinfo->backup_media_type == nfs) { 1133 if (!cfgf) { 1134 log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount); 1135 log_msg(2, "nfs_remote_dir remains %s", 1136 bkpinfo->nfs_remote_dir); 1137 log_msg(2, 1138 "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place"); 1139 } else { 1140 read_cfg_var(g_mondo_cfg_file, "nfs-server-mount", 1141 bkpinfo->nfs_mount); 1142 read_cfg_var(g_mondo_cfg_file, "nfs-server-path", 1143 bkpinfo->nfs_remote_dir); 1144 log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount); 1145 log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir); 1146 } 1147 } else if (bkpinfo->backup_media_type == iso) { 1148 /* Patch by Conor Daly 23-june-2004 1149 * to correctly mount iso-dev and set a sensible 1150 * isodir in disaster recovery mode 1151 */ 1152 strcpy(old_isodir, bkpinfo->isodir); 1153 read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt); 1154 read_cfg_var(g_mondo_cfg_file, "isodir", iso_path); 1155 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1156 if (!bkpinfo->isodir[0]) { 1157 strcpy(bkpinfo->isodir, old_isodir); 1158 } 1159 if (!bkpinfo->disaster_recovery) { 1160 if (strcmp(old_isodir, bkpinfo->isodir)) { 1161 log_it 1162 ("user nominated isodir differs from archive, keeping user's choice: %s %s\n", 1163 old_isodir, bkpinfo->isodir); 1164 strcpy(bkpinfo->isodir, old_isodir); 1165 } 1166 } 1167 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); 1168 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, 1169 g_isodir_device); 1170 if (bkpinfo->disaster_recovery) { 1171 if (is_this_device_mounted(g_isodir_device)) { 1172 log_msg(2, "NB: isodir is already mounted"); 1173 /* Find out where it's mounted */ 1174 sprintf(command, 1175 "mount | grep -w %s | tail -n1 | cut -d' ' -f3", 1176 g_isodir_device); 1177 log_it("command = %s", command); 1178 log_it("res of it = %s", 1179 call_program_and_get_last_line_of_output(command)); 1180 sprintf(iso_mnt, "%s", 1181 call_program_and_get_last_line_of_output(command)); 1182 } else { 1183 sprintf(iso_mnt, "/tmp/isodir"); 1184 sprintf(tmp, "mkdir -p %s", iso_mnt); 1185 run_program_and_log_output(tmp, 5); 1186 sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt); 1187 if (run_program_and_log_output(tmp, 3)) { 1188 log_msg(1, 1189 "Unable to mount isodir. Perhaps this is really a CD backup?"); 1190 bkpinfo->backup_media_type = cdr; 1191 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* superfluous */ 1192 bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0'; 1193 if (mount_cdrom(bkpinfo)) { 1194 fatal_error 1195 ("Unable to mount isodir. Failed to mount CD-ROM as well."); 1196 } else { 1197 log_msg(1, 1198 "You backed up to disk, then burned some CDs. Naughty monkey!"); 1199 } 1200 } 1201 } 1202 /* bkpinfo->isodir should now be the true path to 1.iso etc... */ 1203 if (bkpinfo->backup_media_type == iso) { 1204 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1205 } 1206 } 1207 } 1208 1209 if (media_specified_by_user != none) { 1210 if (g_restoring_live_from_cd) { 1211 if (bkpinfo->backup_media_type != media_specified_by_user) { 1212 log_msg(2, 1213 "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)"); 1214 interactively_obtain_media_parameters_from_user(bkpinfo, 1215 FALSE); 1216 media_specified_by_user = bkpinfo->backup_media_type; 1217 get_cfg_file_from_archive(bkpinfo); 1270 1218 /* 1271 1219 if (media_specified_by_user != cdr && media_specified_by_user == cdrw) 1272 1220 { g_restoring_live_from_cd = FALSE; } 1273 1221 */ 1274 } 1275 } 1276 bkpinfo->backup_media_type = media_specified_by_user; 1277 } 1278 g_backup_media_type = bkpinfo->backup_media_type; 1279 paranoid_free(value); 1280 paranoid_free(tmp); 1281 paranoid_free(command); 1282 paranoid_free(iso_mnt); 1283 paranoid_free(iso_path); 1284 paranoid_free(old_isodir); 1285 return( 0 ); 1286 1287 } 1222 } 1223 } 1224 bkpinfo->backup_media_type = media_specified_by_user; 1225 } 1226 g_backup_media_type = bkpinfo->backup_media_type; 1227 paranoid_free(value); 1228 paranoid_free(tmp); 1229 paranoid_free(command); 1230 paranoid_free(iso_mnt); 1231 paranoid_free(iso_path); 1232 paranoid_free(old_isodir); 1233 return (0); 1234 1235 } 1236 1288 1237 /************************************************************************** 1289 1238 *END_READ_CFG_FILE_INTO_BKPINFO * … … 1291 1240 1292 1241 1293 1242 1294 1243 1295 1244 /** … … 1304 1253 */ 1305 1254 struct 1306 s_node *process_filelist_and_biggielist( struct s_bkpinfo *bkpinfo)1307 { 1308 1255 s_node *process_filelist_and_biggielist(struct s_bkpinfo *bkpinfo) 1256 { 1257 struct s_node *filelist; 1309 1258 1310 1259 /** add mallocs**/ 1311 char *command; 1312 char *tmp; 1313 int res=0; 1314 pid_t pid; 1315 1316 assert(bkpinfo!=NULL); 1317 malloc_string(command); 1318 malloc_string(tmp); 1319 1320 if ( does_file_exist( g_filelist_full ) && does_file_exist( g_biggielist_txt ) ) 1321 { 1322 log_msg(1, "%s exists", g_filelist_full); 1323 log_msg(1, "%s exists", g_biggielist_txt); 1324 log_msg(2, "Filelist and biggielist already recovered from media. Yay!" ); 1325 } 1326 else 1327 { 1328 getcwd( tmp, MAX_STR_LEN ); 1329 chdir( bkpinfo->tmpdir ); 1330 log_msg(1, "chdir(%s)", bkpinfo->tmpdir); 1331 log_to_screen( "Extracting filelist and biggielist from media..." ); 1332 unlink("/tmp/filelist.full"); 1333 unlink("/" FILELIST_FULL_STUB); 1334 unlink("/tmp/i-want-my-lvm"); 1335 if ( IS_THIS_A_STREAMING_BACKUP( bkpinfo->backup_media_type ) ) 1336 { 1337 sprintf( command, 1338 "tar -zxf %s %s %s %s %s %s", 1339 bkpinfo->media_device, 1340 MOUNTLIST_FNAME_STUB, 1341 BIGGIELIST_TXT_STUB, 1342 FILELIST_FULL_STUB, 1343 "tmp/i-want-my-lvm", 1344 MONDO_CFG_FILE_STUB); 1345 log_msg(1, "tarcommand = %s", command); 1346 run_program_and_log_output( command, 1 ); 1347 } 1348 else 1349 { 1350 log_msg(2,"Calling insist_on_this_cd_number; bkpinfo->isodir=%s", bkpinfo->isodir); 1351 insist_on_this_cd_number( bkpinfo, 1 ); 1352 log_msg(2, "Back from iotcn"); 1353 run_program_and_log_output("mount", 1); 1354 sprintf( command, 1355 "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", 1356 MNT_CDROM, 1357 MOUNTLIST_FNAME_STUB, 1358 BIGGIELIST_TXT_STUB, 1359 FILELIST_FULL_STUB, 1360 "tmp/i-want-my-lvm", 1361 MONDO_CFG_FILE_STUB); 1362 1363 log_msg(1, "tarcommand = %s", command); 1364 run_program_and_log_output(command, 1); 1365 // popup_and_OK("Press ENTER to continue"); 1366 if ( !does_file_exist( BIGGIELIST_TXT_STUB ) ) 1367 { 1368 fatal_error( "all.tar.gz did not include tmp/biggielist.txt"); 1369 } 1370 if ( !does_file_exist( FILELIST_FULL_STUB ) ) 1371 { 1372 fatal_error( "all.tar.gz did not include tmp/filelist.full.gz"); 1373 } 1374 } 1375 sprintf( command, "cp -f %s %s", MONDO_CFG_FILE_STUB, g_mondo_cfg_file ); 1376 run_program_and_log_output( command, FALSE ); 1377 1378 sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB, g_biggielist_txt); 1379 log_msg(1, "command = %s", command); 1380 paranoid_system(command); 1381 sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, FILELIST_FULL_STUB, g_filelist_full); 1382 log_msg(1, "command = %s", command); 1383 paranoid_system(command); 1384 } 1385 1386 if (am_I_in_disaster_recovery_mode() && ask_me_yes_or_no("Do you want to retrieve the mountlist as well?")) 1387 { 1260 char *command; 1261 char *tmp; 1262 int res = 0; 1263 pid_t pid; 1264 1265 assert(bkpinfo != NULL); 1266 malloc_string(command); 1267 malloc_string(tmp); 1268 1269 if (does_file_exist(g_filelist_full) 1270 && does_file_exist(g_biggielist_txt)) { 1271 log_msg(1, "%s exists", g_filelist_full); 1272 log_msg(1, "%s exists", g_biggielist_txt); 1273 log_msg(2, 1274 "Filelist and biggielist already recovered from media. Yay!"); 1275 } else { 1276 getcwd(tmp, MAX_STR_LEN); 1277 chdir(bkpinfo->tmpdir); 1278 log_msg(1, "chdir(%s)", bkpinfo->tmpdir); 1279 log_to_screen("Extracting filelist and biggielist from media..."); 1280 unlink("/tmp/filelist.full"); 1281 unlink("/" FILELIST_FULL_STUB); 1282 unlink("/tmp/i-want-my-lvm"); 1283 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1284 sprintf(command, 1285 "tar -zxf %s %s %s %s %s %s", 1286 bkpinfo->media_device, 1287 MOUNTLIST_FNAME_STUB, 1288 BIGGIELIST_TXT_STUB, 1289 FILELIST_FULL_STUB, 1290 "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB); 1291 log_msg(1, "tarcommand = %s", command); 1292 run_program_and_log_output(command, 1); 1293 } else { 1294 log_msg(2, 1295 "Calling insist_on_this_cd_number; bkpinfo->isodir=%s", 1296 bkpinfo->isodir); 1297 insist_on_this_cd_number(bkpinfo, 1); 1298 log_msg(2, "Back from iotcn"); 1299 run_program_and_log_output("mount", 1); 1300 sprintf(command, 1301 "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", 1302 MNT_CDROM, 1303 MOUNTLIST_FNAME_STUB, 1304 BIGGIELIST_TXT_STUB, 1305 FILELIST_FULL_STUB, 1306 "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB); 1307 1308 log_msg(1, "tarcommand = %s", command); 1309 run_program_and_log_output(command, 1); 1310 // popup_and_OK("Press ENTER to continue"); 1311 if (!does_file_exist(BIGGIELIST_TXT_STUB)) { 1312 fatal_error 1313 ("all.tar.gz did not include tmp/biggielist.txt"); 1314 } 1315 if (!does_file_exist(FILELIST_FULL_STUB)) { 1316 fatal_error 1317 ("all.tar.gz did not include tmp/filelist.full.gz"); 1318 } 1319 } 1320 sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB, 1321 g_mondo_cfg_file); 1322 run_program_and_log_output(command, FALSE); 1323 1324 sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, 1325 BIGGIELIST_TXT_STUB, g_biggielist_txt); 1326 log_msg(1, "command = %s", command); 1327 paranoid_system(command); 1328 sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, 1329 FILELIST_FULL_STUB, g_filelist_full); 1330 log_msg(1, "command = %s", command); 1331 paranoid_system(command); 1332 } 1333 1334 if (am_I_in_disaster_recovery_mode() 1335 && 1336 ask_me_yes_or_no("Do you want to retrieve the mountlist as well?")) 1337 { 1388 1338 // sprintf(command, "cp -f tmp/mountlist.txt /tmp"); 1389 sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir); 1390 paranoid_system(command); 1391 } 1392 1393 chdir( tmp ); 1394 1395 if (!does_file_exist( g_biggielist_txt) ) 1396 { 1397 log_msg(1, "Warning - %s not found", g_biggielist_txt); 1398 } 1399 if (!does_file_exist(g_filelist_full) ) 1400 { 1401 log_msg(1, "Warning - %s does not exist", g_filelist_full); 1402 } 1403 1339 sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, 1340 bkpinfo->tmpdir); 1341 paranoid_system(command); 1342 } 1343 1344 chdir(tmp); 1345 1346 if (!does_file_exist(g_biggielist_txt)) { 1347 log_msg(1, "Warning - %s not found", g_biggielist_txt); 1348 } 1349 if (!does_file_exist(g_filelist_full)) { 1350 log_msg(1, "Warning - %s does not exist", g_filelist_full); 1351 } 1404 1352 // popup_and_OK("Wonderful."); 1405 1353 1406 log_msg(2, "Forking" ); 1407 pid = fork(); 1408 switch( pid ) 1409 { 1410 case -1: 1411 fatal_error("Forking error"); 1412 break; 1413 1414 case 0: 1415 log_to_screen("Pre-processing filelist"); 1416 if (!does_file_exist(g_biggielist_txt)) 1417 { 1418 sprintf(command,"> %s",g_biggielist_txt); 1419 paranoid_system(command); 1420 } 1421 sprintf(command,"cat %s | grep -x \"/dev/.*\" > %s", g_biggielist_txt, g_filelist_imagedevs); 1422 paranoid_system(command); 1423 exit( 0 ); 1424 break; 1425 1426 default: 1427 open_evalcall_form("Pre-processing filelist"); 1428 while( !waitpid( pid, (int*)0, WNOHANG ) ) 1429 { 1430 usleep( 100000 ); 1431 update_evalcall_form( 0 ); 1432 } 1433 } 1434 close_evalcall_form(); 1435 1436 log_msg(3, "loading filelist"); 1437 filelist = load_filelist( g_filelist_full ); 1438 log_msg(3, "deleting original filelist"); 1439 unlink(g_filelist_full); 1440 if (g_text_mode) 1441 { 1442 printf("Restore which directory? --> "); 1443 fgets(tmp, sizeof(tmp), stdin); 1444 toggle_path_selection (filelist, tmp, TRUE); 1445 if (strlen(tmp)==0) { res=1; } else { res=0; } 1446 } 1447 else 1448 { 1449 res = edit_filelist( filelist ); 1450 } 1451 if (res) 1452 { 1453 log_msg(2, "User hit 'cancel'. Freeing filelist and aborting."); 1454 free_filelist( filelist ); 1455 return( NULL ); 1456 } 1457 ask_about_these_imagedevs( g_filelist_imagedevs, g_imagedevs_restthese ); 1458 close_evalcall_form(); 1459 1460 // NB: It's not necessary to add g_biggielist_txt to the filelist.full 1461 // file. The filelist.full file already contains the filename of EVERY 1462 // file backed up - regular and biggie files. 1463 1464 // However, we do want to make sure the imagedevs selected by the user 1465 // are flagged for restoring. 1466 if ( length_of_file( g_imagedevs_restthese ) > 2 ) 1467 { add_list_of_files_to_filelist(filelist, g_imagedevs_restthese, TRUE); } 1468 1469 paranoid_free(command); 1470 paranoid_free(tmp); 1471 return( filelist ); 1472 } 1354 log_msg(2, "Forking"); 1355 pid = fork(); 1356 switch (pid) { 1357 case -1: 1358 fatal_error("Forking error"); 1359 break; 1360 1361 case 0: 1362 log_to_screen("Pre-processing filelist"); 1363 if (!does_file_exist(g_biggielist_txt)) { 1364 sprintf(command, "> %s", g_biggielist_txt); 1365 paranoid_system(command); 1366 } 1367 sprintf(command, "cat %s | grep -x \"/dev/.*\" > %s", 1368 g_biggielist_txt, g_filelist_imagedevs); 1369 paranoid_system(command); 1370 exit(0); 1371 break; 1372 1373 default: 1374 open_evalcall_form("Pre-processing filelist"); 1375 while (!waitpid(pid, (int *) 0, WNOHANG)) { 1376 usleep(100000); 1377 update_evalcall_form(0); 1378 } 1379 } 1380 close_evalcall_form(); 1381 1382 log_msg(3, "loading filelist"); 1383 filelist = load_filelist(g_filelist_full); 1384 log_msg(3, "deleting original filelist"); 1385 unlink(g_filelist_full); 1386 if (g_text_mode) { 1387 printf("Restore which directory? --> "); 1388 fgets(tmp, sizeof(tmp), stdin); 1389 toggle_path_selection(filelist, tmp, TRUE); 1390 if (strlen(tmp) == 0) { 1391 res = 1; 1392 } else { 1393 res = 0; 1394 } 1395 } else { 1396 res = edit_filelist(filelist); 1397 } 1398 if (res) { 1399 log_msg(2, "User hit 'cancel'. Freeing filelist and aborting."); 1400 free_filelist(filelist); 1401 return (NULL); 1402 } 1403 ask_about_these_imagedevs(g_filelist_imagedevs, g_imagedevs_restthese); 1404 close_evalcall_form(); 1405 1406 // NB: It's not necessary to add g_biggielist_txt to the filelist.full 1407 // file. The filelist.full file already contains the filename of EVERY 1408 // file backed up - regular and biggie files. 1409 1410 // However, we do want to make sure the imagedevs selected by the user 1411 // are flagged for restoring. 1412 if (length_of_file(g_imagedevs_restthese) > 2) { 1413 add_list_of_files_to_filelist(filelist, g_imagedevs_restthese, 1414 TRUE); 1415 } 1416 1417 paranoid_free(command); 1418 paranoid_free(tmp); 1419 return (filelist); 1420 } 1421 1473 1422 /************************************************************************** 1474 1423 *END_ PROCESS_FILELIST_AND_BIGGIELIST * … … 1485 1434 * @return 0 for success, nonzero for failure. 1486 1435 */ 1487 int backup_crucial_file(char *path_root, char *filename)1488 { 1489 1490 1491 1492 1493 1494 1495 assert(path_root!=NULL);1496 1497 1498 1499 1500 1501 1502 1503 1504 return(res);1436 int backup_crucial_file(char *path_root, char *filename) 1437 { 1438 char *tmp; 1439 char *command; 1440 int res; 1441 1442 malloc_string(tmp); 1443 malloc_string(command); 1444 assert(path_root != NULL); 1445 assert_string_is_neither_NULL_nor_zerolength(filename); 1446 1447 sprintf(tmp, "%s/%s", path_root, filename); 1448 sprintf(command, "cp -f %s %s.pristine", tmp, tmp); 1449 1450 res = run_program_and_log_output(command, 5); 1451 paranoid_free(tmp); 1452 paranoid_free(command); 1453 return (res); 1505 1454 } 1506 1455 … … 1512 1461 * @return 0 for success, nonzero for failure. 1513 1462 */ 1514 int 1515 run_boot_loader(bool offer_to_hack_scripts) 1516 { 1517 int res; 1518 int retval = 0; 1463 int run_boot_loader(bool offer_to_hack_scripts) 1464 { 1465 int res; 1466 int retval = 0; 1519 1467 1520 1468 /** malloc *******/ 1521 char *device; 1522 char *tmp; 1523 char *name; 1524 1525 malloc_string(device); 1526 malloc_string(tmp); 1527 malloc_string(name); 1528 backup_crucial_file( MNT_RESTORING, "/etc/fstab"); 1529 backup_crucial_file( MNT_RESTORING, "/etc/grub.conf"); 1530 backup_crucial_file( MNT_RESTORING, "/etc/lilo.conf"); 1531 backup_crucial_file( MNT_RESTORING, "/etc/elilo.conf"); 1532 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device); 1533 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name); 1534 sprintf(tmp,"run_boot_loader: device='%s', name='%s'",device,name); 1535 log_msg(2, tmp); 1536 system("sync"); 1537 if (!strcmp(name,"LILO")) 1538 { 1539 res = run_lilo(offer_to_hack_scripts); 1540 } 1541 else if (!strcmp(name,"ELILO")) 1542 { 1543 res = run_elilo(offer_to_hack_scripts); 1544 } 1545 else if (!strcmp(name,"GRUB")) 1546 { 1469 char *device; 1470 char *tmp; 1471 char *name; 1472 1473 malloc_string(device); 1474 malloc_string(tmp); 1475 malloc_string(name); 1476 backup_crucial_file(MNT_RESTORING, "/etc/fstab"); 1477 backup_crucial_file(MNT_RESTORING, "/etc/grub.conf"); 1478 backup_crucial_file(MNT_RESTORING, "/etc/lilo.conf"); 1479 backup_crucial_file(MNT_RESTORING, "/etc/elilo.conf"); 1480 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device); 1481 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name); 1482 sprintf(tmp, "run_boot_loader: device='%s', name='%s'", device, name); 1483 log_msg(2, tmp); 1484 system("sync"); 1485 if (!strcmp(name, "LILO")) { 1486 res = run_lilo(offer_to_hack_scripts); 1487 } else if (!strcmp(name, "ELILO")) { 1488 res = run_elilo(offer_to_hack_scripts); 1489 } else if (!strcmp(name, "GRUB")) { 1547 1490 // if ( does_file_exist(DO_MBR_PLEASE) || (offer_to_hack_scripts && ask_me_yes_or_no("Because of bugs in GRUB, you're much better off running mondorestore --mbr after this program terminates. Are you sure you want to install GRUB right now?"))) 1548 1491 // { 1549 1550 // 1551 // 1492 res = run_grub(offer_to_hack_scripts, device); 1493 // unlink(DO_MBR_PLEASE); 1494 // } 1552 1495 // else 1553 1496 // { 1554 // log_msg(1, "Not running run_grub(). Was a bad idea anyway."); 1555 // res = 1; 1556 // } 1557 } 1558 else if (!strcmp(name,"RAW")) 1559 { 1560 res = run_raw_mbr(offer_to_hack_scripts, device); 1561 } 1497 // log_msg(1, "Not running run_grub(). Was a bad idea anyway."); 1498 // res = 1; 1499 // } 1500 } else if (!strcmp(name, "RAW")) { 1501 res = run_raw_mbr(offer_to_hack_scripts, device); 1502 } 1562 1503 #ifdef __FreeBSD__ 1563 else if (!strcmp(name,"BOOT0")) 1564 { 1565 sprintf (tmp, "boot0cfg -B %s", device);1566 res = run_program_and_log_output (tmp, FALSE);1567 } else { 1568 sprintf (tmp, "ls /dev | grep -xq %ss[1-4].*", device);1569 if (!system (tmp)) {1570 sprintf (tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);1571 res = run_program_and_log_output (tmp, 3);1572 } else {1573 log_msg (1,"I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");1574 1575 1504 else if (!strcmp(name, "BOOT0")) { 1505 sprintf(tmp, "boot0cfg -B %s", device); 1506 res = run_program_and_log_output(tmp, FALSE); 1507 } else { 1508 sprintf(tmp, "ls /dev | grep -xq %ss[1-4].*", device); 1509 if (!system(tmp)) { 1510 sprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device); 1511 res = run_program_and_log_output(tmp, 3); 1512 } else { 1513 log_msg(1, 1514 "I'm not running any boot loader. You have a DD boot drive. It's already loaded up."); 1515 } 1516 } 1576 1517 #else 1577 else 1578 { 1579 log_to_screen("Unable to determine type of boot loader. Defaulting to LILO.");1580 res=run_lilo(offer_to_hack_scripts);1581 1518 else { 1519 log_to_screen 1520 ("Unable to determine type of boot loader. Defaulting to LILO."); 1521 res = run_lilo(offer_to_hack_scripts); 1522 } 1582 1523 #endif 1583 retval += res; 1584 if (res) 1585 { 1586 log_to_screen("Your boot loader returned an error"); 1587 } 1588 else 1589 { 1590 log_to_screen("Your boot loader ran OK"); 1591 } 1592 paranoid_free(device); 1593 paranoid_free(tmp); 1594 paranoid_free(name); 1595 return(retval); 1596 } 1524 retval += res; 1525 if (res) { 1526 log_to_screen("Your boot loader returned an error"); 1527 } else { 1528 log_to_screen("Your boot loader ran OK"); 1529 } 1530 paranoid_free(device); 1531 paranoid_free(tmp); 1532 paranoid_free(name); 1533 return (retval); 1534 } 1535 1597 1536 /************************************************************************** 1598 1537 *END_ RUN_BOOT_LOADER * … … 1608 1547 char *find_my_editor(void) 1609 1548 { 1610 static char output[MAX_STR_LEN]; 1611 if (find_home_of_exe("pico")) 1612 { strcpy(output, "pico"); } 1613 else if (find_home_of_exe("nano")) 1614 { strcpy(output, "nano"); } 1615 else if (find_home_of_exe ("e3em")) 1616 { 1617 strcpy (output, "e3em"); 1618 } 1619 else if (find_home_of_exe ("e3vi")) 1620 { 1621 strcpy (output, "e3vi"); 1622 } 1623 else 1624 { strcpy(output, "vi"); } 1625 if (!find_home_of_exe(output)) 1626 { log_msg(2, " (find_my_editor) --- warning - %s not found", output); } 1627 return(output); 1549 static char output[MAX_STR_LEN]; 1550 if (find_home_of_exe("pico")) { 1551 strcpy(output, "pico"); 1552 } else if (find_home_of_exe("nano")) { 1553 strcpy(output, "nano"); 1554 } else if (find_home_of_exe("e3em")) { 1555 strcpy(output, "e3em"); 1556 } else if (find_home_of_exe("e3vi")) { 1557 strcpy(output, "e3vi"); 1558 } else { 1559 strcpy(output, "vi"); 1560 } 1561 if (!find_home_of_exe(output)) { 1562 log_msg(2, " (find_my_editor) --- warning - %s not found", output); 1563 } 1564 return (output); 1628 1565 } 1629 1566 … … 1635 1572 * @return 0 for success, nonzero for failure. 1636 1573 */ 1637 int 1638 run_grub(bool offer_to_run_stabgrub, char*bd) 1574 int run_grub(bool offer_to_run_stabgrub, char *bd) 1639 1575 { 1640 1576 /** malloc **/ 1641 char *command; 1642 char *boot_device; 1643 char *rootdev; 1644 char *rootdrive; 1645 char *conffile; 1646 char *tmp; 1647 char *editor; 1648 1649 int res; 1650 int done; 1651 1652 malloc_string(command); 1653 malloc_string(boot_device); 1654 malloc_string(tmp); 1655 malloc_string(editor); 1656 malloc_string(rootdev); 1657 malloc_string(rootdrive); 1658 malloc_string(conffile); 1659 assert_string_is_neither_NULL_nor_zerolength(bd); 1660 strcpy( editor, "vi" ); // find_my_editor() ); 1661 strcpy( boot_device, bd); 1662 1663 if (!run_program_and_log_output("which grub-MR", FALSE)) 1664 { 1665 log_msg(1, "Yay! grub-MR found..."); 1666 sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device); 1667 log_msg(1, "command = %s", command); 1668 } 1669 else 1670 { 1671 sprintf(command, "chroot " MNT_RESTORING " grub-install %s",boot_device); 1672 log_msg(1, "WARNING - grub-MR not found; using grub-install"); 1673 } 1674 if (offer_to_run_stabgrub && ask_me_yes_or_no("Did you change the mountlist?")) 1675 /* interactive mode */ 1676 { 1677 mvaddstr_and_log_it(g_currentY, 1678 0, 1679 "Modifying fstab and grub.conf, and running GRUB... "); 1680 for(done = FALSE; !done; ) 1577 char *command; 1578 char *boot_device; 1579 char *rootdev; 1580 char *rootdrive; 1581 char *conffile; 1582 char *tmp; 1583 char *editor; 1584 1585 int res; 1586 int done; 1587 1588 malloc_string(command); 1589 malloc_string(boot_device); 1590 malloc_string(tmp); 1591 malloc_string(editor); 1592 malloc_string(rootdev); 1593 malloc_string(rootdrive); 1594 malloc_string(conffile); 1595 assert_string_is_neither_NULL_nor_zerolength(bd); 1596 strcpy(editor, "vi"); // find_my_editor() ); 1597 strcpy(boot_device, bd); 1598 1599 if (!run_program_and_log_output("which grub-MR", FALSE)) { 1600 log_msg(1, "Yay! grub-MR found..."); 1601 sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device); 1602 log_msg(1, "command = %s", command); 1603 } else { 1604 sprintf(command, "chroot " MNT_RESTORING " grub-install %s", 1605 boot_device); 1606 log_msg(1, "WARNING - grub-MR not found; using grub-install"); 1607 } 1608 if (offer_to_run_stabgrub 1609 && ask_me_yes_or_no("Did you change the mountlist?")) 1610 /* interactive mode */ 1681 1611 { 1682 popup_and_get_string("Boot device", 1683 "Please confirm/enter the boot device. If in doubt, try /dev/hda", 1684 boot_device, MAX_STR_LEN/4); 1685 sprintf(command, "stabgrub-me %s", boot_device); 1686 res = run_program_and_log_output(command, 1); 1687 if (res) 1688 { 1689 popup_and_OK("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done."); 1690 newtSuspend(); 1691 system("chroot " MNT_RESTORING); 1692 newtResume(); 1693 popup_and_OK("Thank you."); 1694 } 1695 else 1696 { 1697 done = TRUE; 1698 } 1699 popup_and_OK("You will now edit fstab and grub.conf"); 1700 if (!g_text_mode) { newtSuspend(); } 1701 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1702 paranoid_system(tmp); 1703 sprintf(tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor); 1704 paranoid_system(tmp); 1705 if (!g_text_mode) { newtResume(); } 1706 } 1707 } 1708 else 1709 1710 /* nuke mode */ 1711 { 1712 mvaddstr_and_log_it(g_currentY, 1713 0, 1714 "Running GRUB... "); 1715 iamhere(command); 1716 res = run_program_and_log_output(command, 1); 1717 if (res) 1612 mvaddstr_and_log_it(g_currentY, 1613 0, 1614 "Modifying fstab and grub.conf, and running GRUB... "); 1615 for (done = FALSE; !done;) { 1616 popup_and_get_string("Boot device", 1617 "Please confirm/enter the boot device. If in doubt, try /dev/hda", 1618 boot_device, MAX_STR_LEN / 4); 1619 sprintf(command, "stabgrub-me %s", boot_device); 1620 res = run_program_and_log_output(command, 1); 1621 if (res) { 1622 popup_and_OK 1623 ("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done."); 1624 newtSuspend(); 1625 system("chroot " MNT_RESTORING); 1626 newtResume(); 1627 popup_and_OK("Thank you."); 1628 } else { 1629 done = TRUE; 1630 } 1631 popup_and_OK("You will now edit fstab and grub.conf"); 1632 if (!g_text_mode) { 1633 newtSuspend(); 1634 } 1635 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1636 paranoid_system(tmp); 1637 sprintf(tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor); 1638 paranoid_system(tmp); 1639 if (!g_text_mode) { 1640 newtResume(); 1641 } 1642 } 1643 } else 1644 /* nuke mode */ 1718 1645 { 1719 popup_and_OK("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished."); 1720 newtSuspend(); 1721 system("chroot " MNT_RESTORING); 1722 newtResume(); 1723 popup_and_OK("Thank you."); 1724 } 1725 } 1726 if (res) 1727 { 1728 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1729 log_to_screen("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info."); 1730 log_msg(1,"Type:-"); 1731 log_msg(1," mount-me"); 1732 log_msg(1," chroot " MNT_RESTORING); 1733 log_msg(1," mount /boot"); 1734 log_msg(1," grub-install '(hd0)'"); 1735 log_msg(1," exit"); 1736 log_msg(1," unmount-me"); 1737 log_msg(1,"If you're really stuck, please e-mail the mailing list."); 1738 } 1739 else 1740 { 1741 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1742 } 1743 paranoid_free(rootdev); 1744 paranoid_free(rootdrive); 1745 paranoid_free(conffile); 1746 paranoid_free(command); 1747 paranoid_free(boot_device); 1748 paranoid_free(tmp); 1749 paranoid_free(editor); 1750 1751 return( res ); 1752 } 1646 mvaddstr_and_log_it(g_currentY, 1647 0, 1648 "Running GRUB... "); 1649 iamhere(command); 1650 res = run_program_and_log_output(command, 1); 1651 if (res) { 1652 popup_and_OK 1653 ("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished."); 1654 newtSuspend(); 1655 system("chroot " MNT_RESTORING); 1656 newtResume(); 1657 popup_and_OK("Thank you."); 1658 } 1659 } 1660 if (res) { 1661 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1662 log_to_screen 1663 ("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info."); 1664 log_msg(1, "Type:-"); 1665 log_msg(1, " mount-me"); 1666 log_msg(1, " chroot " MNT_RESTORING); 1667 log_msg(1, " mount /boot"); 1668 log_msg(1, " grub-install '(hd0)'"); 1669 log_msg(1, " exit"); 1670 log_msg(1, " unmount-me"); 1671 log_msg(1, 1672 "If you're really stuck, please e-mail the mailing list."); 1673 } else { 1674 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1675 } 1676 paranoid_free(rootdev); 1677 paranoid_free(rootdrive); 1678 paranoid_free(conffile); 1679 paranoid_free(command); 1680 paranoid_free(boot_device); 1681 paranoid_free(tmp); 1682 paranoid_free(editor); 1683 1684 return (res); 1685 } 1686 1753 1687 /************************************************************************** 1754 1688 *END_RUN_GRUB * … … 1761 1695 * @return 0 for success, nonzero for failure. 1762 1696 */ 1763 int 1764 run_elilo(bool offer_to_run_stabelilo) 1697 int run_elilo(bool offer_to_run_stabelilo) 1765 1698 { 1766 1699 /** malloc **/ 1767 char *command; 1768 char *tmp; 1769 char *editor; 1770 1771 int res; 1772 int done; 1773 1774 malloc_string(command); 1775 malloc_string(tmp); 1776 malloc_string(editor); 1777 strcpy(editor, find_my_editor()); 1778 if (offer_to_run_stabelilo && ask_me_yes_or_no("Did you change the mountlist?")) 1779 1780 /* interactive mode */ 1781 { 1782 mvaddstr_and_log_it(g_currentY, 1783 0, 1784 "Modifying fstab and elilo.conf... "); 1785 sprintf(command,"stabelilo-me"); 1786 res = run_program_and_log_output(command, 3); 1787 if (res) 1788 { 1789 popup_and_OK("You will now edit fstab and elilo.conf, to make sure they match your new mountlist."); 1790 for(done = FALSE; !done;) 1791 { 1792 if (!g_text_mode) { newtSuspend(); } 1793 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1794 paranoid_system(tmp); 1795 sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf", editor); 1796 paranoid_system(tmp); 1797 if (!g_text_mode) { newtResume(); } 1700 char *command; 1701 char *tmp; 1702 char *editor; 1703 1704 int res; 1705 int done; 1706 1707 malloc_string(command); 1708 malloc_string(tmp); 1709 malloc_string(editor); 1710 strcpy(editor, find_my_editor()); 1711 if (offer_to_run_stabelilo 1712 && ask_me_yes_or_no("Did you change the mountlist?")) 1713 1714 /* interactive mode */ 1715 { 1716 mvaddstr_and_log_it(g_currentY, 1717 0, 1718 "Modifying fstab and elilo.conf... "); 1719 sprintf(command, "stabelilo-me"); 1720 res = run_program_and_log_output(command, 3); 1721 if (res) { 1722 popup_and_OK 1723 ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist."); 1724 for (done = FALSE; !done;) { 1725 if (!g_text_mode) { 1726 newtSuspend(); 1727 } 1728 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1729 paranoid_system(tmp); 1730 sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf", 1731 editor); 1732 paranoid_system(tmp); 1733 if (!g_text_mode) { 1734 newtResume(); 1735 } 1798 1736 // newtCls(); 1799 if (ask_me_yes_or_no("Edit them again?")) 1800 { 1801 continue; 1802 } 1803 done = TRUE; 1804 } 1805 } 1806 else 1737 if (ask_me_yes_or_no("Edit them again?")) { 1738 continue; 1739 } 1740 done = TRUE; 1741 } 1742 } else { 1743 log_to_screen("elilo.conf and fstab were modified OK"); 1744 } 1745 } else 1746 /* nuke mode */ 1807 1747 { 1808 log_to_screen("elilo.conf and fstab were modified OK"); 1809 } 1810 } 1811 else 1812 1813 /* nuke mode */ 1814 { 1815 res = TRUE; 1816 } 1817 paranoid_free(command); 1818 paranoid_free(tmp); 1819 paranoid_free(editor); 1820 return(res); 1821 } 1748 res = TRUE; 1749 } 1750 paranoid_free(command); 1751 paranoid_free(tmp); 1752 paranoid_free(editor); 1753 return (res); 1754 } 1755 1822 1756 /************************************************************************** 1823 1757 *END_RUN_ELILO * … … 1830 1764 * @return 0 for success, nonzero for failure. 1831 1765 */ 1832 int 1833 run_lilo(bool offer_to_run_stablilo) 1766 int run_lilo(bool offer_to_run_stablilo) 1834 1767 { 1835 1768 /** malloc **/ 1836 char *command; 1837 char *tmp; 1838 char *editor; 1839 1840 int res; 1841 int done; 1842 bool run_lilo_M = FALSE; 1843 malloc_string(command); 1844 malloc_string(tmp); 1845 malloc_string(editor); 1846 1847 if (!run_program_and_log_output("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) 1848 { run_lilo_M = TRUE; } 1849 1850 strcpy(editor, find_my_editor()); 1851 if (offer_to_run_stablilo && ask_me_yes_or_no("Did you change the mountlist?")) 1852 1853 /* interactive mode */ 1854 { 1855 mvaddstr_and_log_it(g_currentY, 1856 0, 1857 "Modifying fstab and lilo.conf, and running LILO... "); 1858 sprintf(command,"stablilo-me"); 1859 res = run_program_and_log_output(command, 3); 1860 if (res) 1861 { 1862 popup_and_OK("You will now edit fstab and lilo.conf, to make sure they match your new mountlist."); 1863 for(done = FALSE; !done;) 1864 { 1865 if (!g_text_mode) { newtSuspend(); } 1866 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1867 paranoid_system(tmp); 1868 sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor); 1869 paranoid_system(tmp); 1870 if (!g_text_mode) { newtResume(); } 1769 char *command; 1770 char *tmp; 1771 char *editor; 1772 1773 int res; 1774 int done; 1775 bool run_lilo_M = FALSE; 1776 malloc_string(command); 1777 malloc_string(tmp); 1778 malloc_string(editor); 1779 1780 if (!run_program_and_log_output 1781 ("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) { 1782 run_lilo_M = TRUE; 1783 } 1784 1785 strcpy(editor, find_my_editor()); 1786 if (offer_to_run_stablilo 1787 && ask_me_yes_or_no("Did you change the mountlist?")) 1788 1789 /* interactive mode */ 1790 { 1791 mvaddstr_and_log_it(g_currentY, 1792 0, 1793 "Modifying fstab and lilo.conf, and running LILO... "); 1794 sprintf(command, "stablilo-me"); 1795 res = run_program_and_log_output(command, 3); 1796 if (res) { 1797 popup_and_OK 1798 ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist."); 1799 for (done = FALSE; !done;) { 1800 if (!g_text_mode) { 1801 newtSuspend(); 1802 } 1803 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1804 paranoid_system(tmp); 1805 sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor); 1806 paranoid_system(tmp); 1807 if (!g_text_mode) { 1808 newtResume(); 1809 } 1871 1810 // newtCls(); 1872 if (ask_me_yes_or_no("Edit them again?")) 1873 { 1874 continue; 1875 } 1876 res = run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", 3); 1877 if (res) 1878 { 1879 res = run_program_and_log_output("chroot " MNT_RESTORING " lilo", 3); 1880 } 1881 if (res) 1882 { 1883 done = ask_me_yes_or_no("LILO failed. Re-edit system files?"); 1884 } 1885 else 1886 { 1887 done = TRUE; 1888 } 1889 } 1890 } 1891 else 1811 if (ask_me_yes_or_no("Edit them again?")) { 1812 continue; 1813 } 1814 res = 1815 run_program_and_log_output("chroot " MNT_RESTORING 1816 " lilo -L", 3); 1817 if (res) { 1818 res = 1819 run_program_and_log_output("chroot " MNT_RESTORING 1820 " lilo", 3); 1821 } 1822 if (res) { 1823 done = 1824 ask_me_yes_or_no 1825 ("LILO failed. Re-edit system files?"); 1826 } else { 1827 done = TRUE; 1828 } 1829 } 1830 } else { 1831 log_to_screen("lilo.conf and fstab were modified OK"); 1832 } 1833 } else 1834 /* nuke mode */ 1892 1835 { 1893 log_to_screen("lilo.conf and fstab were modified OK"); 1894 } 1895 } 1896 else 1897 1898 /* nuke mode */ 1899 { 1900 mvaddstr_and_log_it(g_currentY, 1901 0, 1902 "Running LILO... "); 1903 res = run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", 3); 1904 if (res) 1905 { 1906 res = run_program_and_log_output("chroot " MNT_RESTORING " lilo", 3); 1907 } 1908 if (res) 1909 { 1910 mvaddstr_and_log_it(g_currentY++,74,"Failed."); 1911 log_to_screen("Failed to re-jig fstab and/or lilo. Edit/run manually, please."); 1912 } 1913 else 1914 { 1915 mvaddstr_and_log_it(g_currentY++,74,"Done."); 1916 } 1917 } 1918 if (run_lilo_M) 1919 { 1920 run_program_and_log_output("chroot " MNT_RESTORING " lilo -M /dev/hda", 3); 1921 run_program_and_log_output("chroot " MNT_RESTORING " lilo -M /dev/sda", 3); 1922 } 1923 paranoid_free(command); 1924 paranoid_free(tmp); 1925 paranoid_free(editor); 1926 return(res); 1927 } 1836 mvaddstr_and_log_it(g_currentY, 1837 0, 1838 "Running LILO... "); 1839 res = 1840 run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", 1841 3); 1842 if (res) { 1843 res = 1844 run_program_and_log_output("chroot " MNT_RESTORING " lilo", 1845 3); 1846 } 1847 if (res) { 1848 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1849 log_to_screen 1850 ("Failed to re-jig fstab and/or lilo. Edit/run manually, please."); 1851 } else { 1852 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1853 } 1854 } 1855 if (run_lilo_M) { 1856 run_program_and_log_output("chroot " MNT_RESTORING 1857 " lilo -M /dev/hda", 3); 1858 run_program_and_log_output("chroot " MNT_RESTORING 1859 " lilo -M /dev/sda", 3); 1860 } 1861 paranoid_free(command); 1862 paranoid_free(tmp); 1863 paranoid_free(editor); 1864 return (res); 1865 } 1866 1928 1867 /************************************************************************** 1929 1868 *END_RUN_LILO * … … 1937 1876 * @return 0 for success, nonzero for failure. 1938 1877 */ 1939 int 1940 run_raw_mbr(bool offer_to_hack_scripts, char *bd) 1878 int run_raw_mbr(bool offer_to_hack_scripts, char *bd) 1941 1879 { 1942 1880 /** malloc **/ 1943 char *command; 1944 char *boot_device; 1945 char *tmp; 1946 char *editor; 1947 int res; 1948 int done; 1949 1950 malloc_string(command); 1951 malloc_string(boot_device); 1952 malloc_string(tmp); 1953 malloc_string(editor); 1954 assert_string_is_neither_NULL_nor_zerolength(bd); 1955 1956 strcpy( editor, find_my_editor() ); 1957 strcpy( boot_device, bd ); 1958 sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device); 1959 log_msg(2, "run_raw_mbr() --- command='%s'", command); 1960 1961 if (offer_to_hack_scripts && ask_me_yes_or_no("Did you change the mountlist?")) 1962 /* interactive mode */ 1963 { 1964 mvaddstr_and_log_it(g_currentY,0,"Modifying fstab and restoring MBR... "); 1965 for(done=FALSE; !done; ) 1881 char *command; 1882 char *boot_device; 1883 char *tmp; 1884 char *editor; 1885 int res; 1886 int done; 1887 1888 malloc_string(command); 1889 malloc_string(boot_device); 1890 malloc_string(tmp); 1891 malloc_string(editor); 1892 assert_string_is_neither_NULL_nor_zerolength(bd); 1893 1894 strcpy(editor, find_my_editor()); 1895 strcpy(boot_device, bd); 1896 sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device); 1897 log_msg(2, "run_raw_mbr() --- command='%s'", command); 1898 1899 if (offer_to_hack_scripts 1900 && ask_me_yes_or_no("Did you change the mountlist?")) 1901 /* interactive mode */ 1966 1902 { 1967 if (!run_program_and_log_output("which vi", FALSE)) 1968 { 1969 popup_and_OK("You will now edit fstab"); 1970 if (!g_text_mode) { newtSuspend(); } 1971 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1972 paranoid_system(tmp); 1973 if (!g_text_mode) { newtResume(); } 1903 mvaddstr_and_log_it(g_currentY, 0, 1904 "Modifying fstab and restoring MBR... "); 1905 for (done = FALSE; !done;) { 1906 if (!run_program_and_log_output("which vi", FALSE)) { 1907 popup_and_OK("You will now edit fstab"); 1908 if (!g_text_mode) { 1909 newtSuspend(); 1910 } 1911 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1912 paranoid_system(tmp); 1913 if (!g_text_mode) { 1914 newtResume(); 1915 } 1974 1916 // newtCls(); 1975 } 1976 popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/hda",boot_device, MAX_STR_LEN/4); 1977 sprintf(command, "stabraw-me %s", boot_device); 1978 res = run_program_and_log_output(command, 3); 1979 if (res) 1980 { 1981 done = ask_me_yes_or_no("Modifications failed. Re-try?"); 1982 } 1983 else 1984 { 1985 done = TRUE; 1986 } 1987 } 1988 } 1989 else 1990 1991 /* nuke mode */ 1992 { 1993 mvaddstr_and_log_it(g_currentY,0,"Restoring MBR... "); 1994 res = run_program_and_log_output(command, 3); 1995 } 1996 if (res) 1997 { 1998 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1999 log_to_screen("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info."); 2000 } 2001 else 2002 { 2003 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2004 } 2005 paranoid_free(command); 2006 paranoid_free(boot_device); 2007 paranoid_free(tmp); 2008 paranoid_free(editor); 2009 return(res); 2010 } 1917 } 1918 popup_and_get_string("Boot device", 1919 "Please confirm/enter the boot device. If in doubt, try /dev/hda", 1920 boot_device, MAX_STR_LEN / 4); 1921 sprintf(command, "stabraw-me %s", boot_device); 1922 res = run_program_and_log_output(command, 3); 1923 if (res) { 1924 done = ask_me_yes_or_no("Modifications failed. Re-try?"); 1925 } else { 1926 done = TRUE; 1927 } 1928 } 1929 } else 1930 /* nuke mode */ 1931 { 1932 mvaddstr_and_log_it(g_currentY, 0, 1933 "Restoring MBR... "); 1934 res = run_program_and_log_output(command, 3); 1935 } 1936 if (res) { 1937 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1938 log_to_screen 1939 ("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info."); 1940 } else { 1941 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1942 } 1943 paranoid_free(command); 1944 paranoid_free(boot_device); 1945 paranoid_free(tmp); 1946 paranoid_free(editor); 1947 return (res); 1948 } 1949 2011 1950 /************************************************************************** 2012 1951 *END_RUN_RAW_MBR * … … 2015 1954 2016 1955 2017 2018 1956 1957 2019 1958 /** 2020 1959 * Turn signal trapping on or off. … … 2022 1961 * print a message and exit immediately. 2023 1962 */ 2024 void 2025 set_signals( int on ) 2026 { 2027 int signals[]= { SIGKILL, SIGPIPE, SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGSTOP, 0 }; 2028 int i; 2029 for ( i = 0; signals[i]; i++) 2030 { 2031 if (on) 2032 { 2033 signal( signals[i], terminate_daemon); 2034 } 2035 else 2036 { 2037 signal(signals[i], termination_in_progress); 2038 } 2039 } 1963 void set_signals(int on) 1964 { 1965 int signals[] = 1966 { SIGKILL, SIGPIPE, SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, 1967 SIGSTOP, 0 }; 1968 int i; 1969 for (i = 0; signals[i]; i++) { 1970 if (on) { 1971 signal(signals[i], terminate_daemon); 1972 } else { 1973 signal(signals[i], termination_in_progress); 1974 } 1975 } 2040 1976 } 2041 1977 … … 2051 1987 * - @c bkpinfo->disaster_recovery 2052 1988 */ 2053 void 2054 setup_MR_global_filenames(struct s_bkpinfo *bkpinfo) 2055 { 2056 char *temppath; 2057 2058 assert(bkpinfo!=NULL); 2059 2060 malloc_string ( g_biggielist_txt ); 2061 malloc_string ( g_filelist_full ); 2062 malloc_string ( g_filelist_imagedevs ); 2063 malloc_string ( g_imagedevs_restthese ); 2064 malloc_string ( g_mondo_cfg_file ); 2065 malloc_string ( g_mountlist_fname ); 2066 malloc_string ( g_mondo_home ); 2067 malloc_string ( g_tmpfs_mountpt ); 2068 malloc_string ( g_isodir_device ); 2069 malloc_string ( g_isodir_format ); 2070 2071 temppath = bkpinfo->tmpdir; 2072 2073 sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB); 2074 sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB); 2075 sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath); 1989 void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo) 1990 { 1991 char *temppath; 1992 1993 assert(bkpinfo != NULL); 1994 1995 malloc_string(g_biggielist_txt); 1996 malloc_string(g_filelist_full); 1997 malloc_string(g_filelist_imagedevs); 1998 malloc_string(g_imagedevs_restthese); 1999 malloc_string(g_mondo_cfg_file); 2000 malloc_string(g_mountlist_fname); 2001 malloc_string(g_mondo_home); 2002 malloc_string(g_tmpfs_mountpt); 2003 malloc_string(g_isodir_device); 2004 malloc_string(g_isodir_format); 2005 2006 temppath = bkpinfo->tmpdir; 2007 2008 sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB); 2009 sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB); 2010 sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath); 2076 2011 // sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", temppath); 2077 sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these", temppath); 2078 if (bkpinfo->disaster_recovery) 2079 2080 2081 2082 } 2083 else 2084 { 2085 sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB);2086 sprintf(g_mountlist_fname, "%s/%s", temppath, MOUNTLIST_FNAME_STUB); 2087 2088 } 2012 sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these", 2013 temppath); 2014 if (bkpinfo->disaster_recovery) { 2015 sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB); 2016 sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB); 2017 } else { 2018 sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB); 2019 sprintf(g_mountlist_fname, "%s/%s", temppath, 2020 MOUNTLIST_FNAME_STUB); 2021 } 2022 } 2023 2089 2024 /************************************************************************** 2090 2025 *END_SET_GLOBAL_FILENAME * … … 2098 2033 * @param input_file The input file, a list of changed files created by a compare. 2099 2034 */ 2100 void 2101 streamline_changes_file(char *output_file, char *input_file) 2102 { 2103 FILE *fin; 2104 FILE *fout; 2035 void streamline_changes_file(char *output_file, char *input_file) 2036 { 2037 FILE *fin; 2038 FILE *fout; 2105 2039 /** malloc **/ 2106 char *incoming; 2107 2108 assert_string_is_neither_NULL_nor_zerolength(output_file); 2109 assert_string_is_neither_NULL_nor_zerolength(input_file); 2110 malloc_string(incoming); 2111 2112 if (!(fin=fopen(input_file,"r"))) 2113 { 2114 log_OS_error(input_file); 2115 return; 2116 } 2117 if (!(fout=fopen(output_file,"w"))) 2118 { 2119 fatal_error("cannot open output_file"); 2120 } 2121 for(fgets(incoming,MAX_STR_LEN-1,fin); !feof(fin); fgets(incoming,MAX_STR_LEN-1,fin)) 2122 { 2123 if(strncmp(incoming,"etc/adjtime",11) \ 2124 && strncmp(incoming,"etc/mtab",8) \ 2125 && strncmp(incoming,"tmp/",4) \ 2126 && strncmp(incoming,"boot/map",8) \ 2127 && !strstr(incoming,"incheckentry") \ 2128 && strncmp(incoming,"etc/mail/statistics",19) \ 2129 && strncmp(incoming,"var/",4)) 2130 fprintf(fout,"%s",incoming); /* don't need \n here, for some reason.. */ 2131 } 2132 paranoid_fclose(fout); 2133 paranoid_fclose(fin); 2134 paranoid_free(incoming); 2135 } 2040 char *incoming; 2041 2042 assert_string_is_neither_NULL_nor_zerolength(output_file); 2043 assert_string_is_neither_NULL_nor_zerolength(input_file); 2044 malloc_string(incoming); 2045 2046 if (!(fin = fopen(input_file, "r"))) { 2047 log_OS_error(input_file); 2048 return; 2049 } 2050 if (!(fout = fopen(output_file, "w"))) { 2051 fatal_error("cannot open output_file"); 2052 } 2053 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); 2054 fgets(incoming, MAX_STR_LEN - 1, fin)) { 2055 if (strncmp(incoming, "etc/adjtime", 11) 2056 && strncmp(incoming, "etc/mtab", 8) 2057 && strncmp(incoming, "tmp/", 4) 2058 && strncmp(incoming, "boot/map", 8) 2059 && !strstr(incoming, "incheckentry") 2060 && strncmp(incoming, "etc/mail/statistics", 19) 2061 && strncmp(incoming, "var/", 4)) 2062 fprintf(fout, "%s", incoming); /* don't need \n here, for some reason.. */ 2063 } 2064 paranoid_fclose(fout); 2065 paranoid_fclose(fin); 2066 paranoid_free(incoming); 2067 } 2068 2136 2069 /************************************************************************** 2137 2070 *END_STREAMLINE_CHANGES_FILE * … … 2146 2079 * Prompt the user to support the Mondo project. 2147 2080 */ 2148 void 2149 success_message(void) 2150 { 2151 int i; 2152 /* malloc and ptr */ 2153 char *tmp; 2154 2155 malloc_string(tmp); 2156 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "restore") == NULL) { 2157 if (ask_me_yes_or_no("Have you contributed to the Mondo project financially or in some other way, yet?")) { 2158 log_to_screen("Thank you for supporting Mondo. It goes from strength to strength,"); 2159 log_to_screen("thanks to the support of users like you."); 2160 } 2161 else { 2162 if (ask_me_yes_or_no("Are you or your company willing to consider contributing to Mondo in some way?")) { 2163 popup_and_OK("To support the project which has just performed a valuable service for you, please visit http://www.mondorescue.com; click on 'Download' and then 'PayPal'."); 2164 } 2165 else { 2166 log_to_screen("Free Software, like freedom itself, must be supported or it will be lost."); 2167 log_msg(1, "To your credit, you were honest: you said no, you wouldn't be contributing"); 2168 log_msg(1, "to this project, ever. However, that makes you a freeloader. I bet you're"); 2169 log_msg(1, "the sort of person who likes to sneak into movie theatres..."); 2170 popup_and_OK("If you ever change your mind, you may support this product by going to http://www.mondrescue.com and clicking on 'Download', followed by 'PalPal'."); 2171 } 2172 } 2173 } 2174 2081 void success_message(void) 2082 { 2083 int i; 2084 /* malloc and ptr */ 2085 char *tmp; 2086 2087 malloc_string(tmp); 2088 if (strstr 2089 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 2090 "restore") == NULL) { 2091 if (ask_me_yes_or_no 2092 ("Have you contributed to the Mondo project financially or in some other way, yet?")) 2093 { 2094 log_to_screen 2095 ("Thank you for supporting Mondo. It goes from strength to strength,"); 2096 log_to_screen("thanks to the support of users like you."); 2097 } else { 2098 if (ask_me_yes_or_no 2099 ("Are you or your company willing to consider contributing to Mondo in some way?")) 2100 { 2101 popup_and_OK 2102 ("To support the project which has just performed a valuable service for you, please visit http://www.mondorescue.com; click on 'Download' and then 'PayPal'."); 2103 } else { 2104 log_to_screen 2105 ("Free Software, like freedom itself, must be supported or it will be lost."); 2106 log_msg(1, 2107 "To your credit, you were honest: you said no, you wouldn't be contributing"); 2108 log_msg(1, 2109 "to this project, ever. However, that makes you a freeloader. I bet you're"); 2110 log_msg(1, 2111 "the sort of person who likes to sneak into movie theatres..."); 2112 popup_and_OK 2113 ("If you ever change your mind, you may support this product by going to http://www.mondrescue.com and clicking on 'Download', followed by 'PalPal'."); 2114 } 2115 } 2116 } 2175 2117 #ifdef FREELOADER 2176 i = (int)(random())%32;2118 i = (int) (random()) % 32; 2177 2119 #else 2178 i=1;2120 i = 1; 2179 2121 #endif 2180 2122 2181 if (i!=25) 2182 { 2183 strcpy(tmp,"Mondo has restored your system. Please remove the backup media and reboot."); 2184 } 2185 else 2186 { 2187 strcpy(tmp,"M0nd0 h45 r3570r3d j00r 5y573m. P13453 r3m0v3 7h3 b4ckup m3d14 4nd r3b007."); 2188 } 2189 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "restore") == NULL) { 2190 popup_and_OK(tmp); 2191 } 2192 log_to_screen(tmp); 2193 paranoid_free(tmp); 2194 } 2123 if (i != 25) { 2124 strcpy(tmp, 2125 "Mondo has restored your system. Please remove the backup media and reboot."); 2126 } else { 2127 strcpy(tmp, 2128 "M0nd0 h45 r3570r3d j00r 5y573m. P13453 r3m0v3 7h3 b4ckup m3d14 4nd r3b007."); 2129 } 2130 if (strstr 2131 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 2132 "restore") == NULL) { 2133 popup_and_OK(tmp); 2134 } 2135 log_to_screen(tmp); 2136 paranoid_free(tmp); 2137 } 2138 2195 2139 /************************************************************************** 2196 2140 *END_SUCCESS_MESSAGE * … … 2203 2147 * @param sig The signal we're exiting due to. 2204 2148 */ 2205 void 2206 terminate_daemon(int sig) 2207 { 2208 log_to_screen("Mondorestore is terminating in response to a signal from the OS"); 2209 paranoid_MR_finish(254); 2210 } 2149 void terminate_daemon(int sig) 2150 { 2151 log_to_screen 2152 ("Mondorestore is terminating in response to a signal from the OS"); 2153 paranoid_MR_finish(254); 2154 } 2155 2211 2156 /************************************************************************** 2212 2157 *END_TERMINATE_DAEMON * … … 2217 2162 * Give the user twenty seconds to press Ctrl-Alt-Del before we nuke their drives. 2218 2163 */ 2219 void 2220 twenty_seconds_til_yikes() 2221 { 2222 int i; 2223 /* MALLOC **/ 2224 char *tmp; 2225 2226 malloc_string(tmp); 2227 if (does_file_exist("/tmp/NOPAUSE")) { return; } 2228 open_progress_form("CAUTION", 2229 "Be advised: I am about to ERASE your hard disk(s)!",2230 "You may press Ctrl+Alt+Del to abort safely.",2231 "",2232 2233 for(i = 0; i < 20; i++) 2234 { 2235 g_current_progress = i;2236 sprintf(tmp,"You have %d seconds left to abort.", 20 - i);2237 update_progress_form( tmp);2238 sleep( 1 ); 2239 } 2240 close_progress_form();2241 paranoid_free(tmp); 2242 } 2164 void twenty_seconds_til_yikes() 2165 { 2166 int i; 2167 /* MALLOC * */ 2168 char *tmp; 2169 2170 malloc_string(tmp); 2171 if (does_file_exist("/tmp/NOPAUSE")) { 2172 return; 2173 } 2174 open_progress_form("CAUTION", 2175 "Be advised: I am about to ERASE your hard disk(s)!", 2176 "You may press Ctrl+Alt+Del to abort safely.", 2177 "", 20); 2178 for (i = 0; i < 20; i++) { 2179 g_current_progress = i; 2180 sprintf(tmp, "You have %d seconds left to abort.", 20 - i); 2181 update_progress_form(tmp); 2182 sleep(1); 2183 } 2184 close_progress_form(); 2185 paranoid_free(tmp); 2186 } 2187 2243 2188 /************************************************************************** 2244 2189 *END_TWENTY_SECONDS_TIL_YIKES * … … 2253 2198 * @param sig The signal we're exiting due to. 2254 2199 */ 2255 void 2256 termination_in_progress(int sig) 2257 { 2258 log_msg(1, "Termination in progress");2259 usleep(1000);2260 pthread_exit(0); 2261 } 2200 void termination_in_progress(int sig) 2201 { 2202 log_msg(1, "Termination in progress"); 2203 usleep(1000); 2204 pthread_exit(0); 2205 } 2206 2262 2207 /************************************************************************** 2263 2208 *END_TERMINATION_IN_PROGRESS * … … 2271 2216 * @return 0 for success, nonzero for failure. 2272 2217 */ 2273 int unmount_all_devices(struct mountlist_itself *p_external_copy_of_mountlist) 2274 { 2275 struct mountlist_itself *mountlist; 2276 int retval=0,lino,res=0,i; 2277 char *command; 2278 char *tmp; 2279 2280 malloc_string(command); 2281 malloc_string(tmp); 2282 assert(p_external_copy_of_mountlist!=NULL); 2283 2284 mountlist = malloc(sizeof(struct mountlist_itself)); 2285 memcpy((void*)mountlist, (void*)p_external_copy_of_mountlist, sizeof(struct mountlist_itself)); 2286 sort_mountlist_by_mountpoint(mountlist, 0); 2287 2288 run_program_and_log_output("df -m", 3); 2289 mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices "); 2290 open_progress_form("Unmounting devices", 2291 "Unmounting all devices that were mounted," , 2292 "in preparation for the post-restoration reboot.", 2293 "", 2294 mountlist->entries); 2295 chdir( "/" ); 2296 for(i = 0; i < 10 && run_program_and_log_output("ps wax | grep buffer | grep -v \"grep buffer\"", TRUE) == 0; i++) 2297 { 2298 sleep( 1 ); 2299 log_msg(2, "Waiting for buffer() to finish"); 2300 } 2301 2302 paranoid_system("sync"); 2303 2304 if (run_program_and_log_output( "cp -f /tmp/mondo-restore.log " MNT_RESTORING "/tmp/", FALSE ) ) 2305 { 2306 log_msg(1, "Error. Failed to copy log to PC's /tmp dir. (Mounted read-only?)"); 2307 } 2308 if (run_program_and_log_output( "cp -f /tmp/mondo-restore.log " MNT_RESTORING "/root/", FALSE ) ) 2309 { 2310 log_msg(1, "Error. Failed to copy log to PC's /root dir. (Mounted read-only?)"); 2311 } 2312 if (does_file_exist("/tmp/DUMBASS-GENTOO")) 2313 { 2314 run_program_and_log_output("mkdir -p " MNT_RESTORING "/mnt/.boot.d", 5); 2315 } 2316 for( lino = mountlist->entries-1; lino >= 0; lino-- ) 2317 { 2318 if (!strcmp(mountlist->el[lino].mountpoint,"lvm")) 2319 { 2320 continue; 2321 } 2322 sprintf(tmp,"Unmounting device %s ",mountlist->el[lino].device); 2323 2324 update_progress_form(tmp); 2325 if (is_this_device_mounted(mountlist->el[lino].device)) 2326 { 2327 if (!strcmp(mountlist->el[lino].mountpoint,"swap")) 2328 { 2329 sprintf(command,"swapoff %s",mountlist->el[lino].device); 2330 } else { 2331 if (!strcmp (mountlist->el[lino].mountpoint, "/1")) 2332 { 2333 sprintf (command, "umount %s/", MNT_RESTORING); 2334 log_msg (3, "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight..."); 2335 } 2336 else 2337 { 2338 sprintf(command,"umount " MNT_RESTORING "%s",mountlist->el[lino].mountpoint); 2339 } 2340 } 2341 log_msg(10, "The 'umount' command is '%s'", command); 2342 res = run_program_and_log_output(command, 3); 2343 } 2344 else 2345 { 2346 strcat(tmp,"...not mounted anyway :-) OK"); 2347 res = 0; 2348 } 2349 g_current_progress++; 2350 if (res) 2351 { 2352 strcat(tmp,"...Failed"); 2353 retval++; 2354 log_to_screen(tmp); 2355 } 2356 else 2357 { 2358 log_msg(2, tmp); 2359 } 2360 } 2361 close_progress_form(); 2362 if (retval) 2363 { 2364 mvaddstr_and_log_it(g_currentY++, 74, "Failed." ); 2365 } 2366 else 2367 { 2368 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2369 } 2370 if (retval) 2371 { 2372 log_to_screen("Unable to unmount some of your partitions."); 2373 } 2374 else 2375 { 2376 log_to_screen("All partitions were unmounted OK."); 2377 } 2378 free(mountlist); 2379 paranoid_free(command); 2380 paranoid_free(tmp); 2381 return(retval); 2382 } 2218 int unmount_all_devices(struct mountlist_itself 2219 *p_external_copy_of_mountlist) 2220 { 2221 struct mountlist_itself *mountlist; 2222 int retval = 0, lino, res = 0, i; 2223 char *command; 2224 char *tmp; 2225 2226 malloc_string(command); 2227 malloc_string(tmp); 2228 assert(p_external_copy_of_mountlist != NULL); 2229 2230 mountlist = malloc(sizeof(struct mountlist_itself)); 2231 memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist, 2232 sizeof(struct mountlist_itself)); 2233 sort_mountlist_by_mountpoint(mountlist, 0); 2234 2235 run_program_and_log_output("df -m", 3); 2236 mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices "); 2237 open_progress_form("Unmounting devices", 2238 "Unmounting all devices that were mounted,", 2239 "in preparation for the post-restoration reboot.", 2240 "", mountlist->entries); 2241 chdir("/"); 2242 for (i = 0; 2243 i < 10 2244 && 2245 run_program_and_log_output 2246 ("ps wax | grep buffer | grep -v \"grep buffer\"", TRUE) == 0; 2247 i++) { 2248 sleep(1); 2249 log_msg(2, "Waiting for buffer() to finish"); 2250 } 2251 2252 paranoid_system("sync"); 2253 2254 if (run_program_and_log_output 2255 ("cp -f /tmp/mondo-restore.log " MNT_RESTORING "/tmp/", FALSE)) { 2256 log_msg(1, 2257 "Error. Failed to copy log to PC's /tmp dir. (Mounted read-only?)"); 2258 } 2259 if (run_program_and_log_output 2260 ("cp -f /tmp/mondo-restore.log " MNT_RESTORING "/root/", FALSE)) { 2261 log_msg(1, 2262 "Error. Failed to copy log to PC's /root dir. (Mounted read-only?)"); 2263 } 2264 if (does_file_exist("/tmp/DUMBASS-GENTOO")) { 2265 run_program_and_log_output("mkdir -p " MNT_RESTORING 2266 "/mnt/.boot.d", 5); 2267 } 2268 for (lino = mountlist->entries - 1; lino >= 0; lino--) { 2269 if (!strcmp(mountlist->el[lino].mountpoint, "lvm")) { 2270 continue; 2271 } 2272 sprintf(tmp, "Unmounting device %s ", mountlist->el[lino].device); 2273 2274 update_progress_form(tmp); 2275 if (is_this_device_mounted(mountlist->el[lino].device)) { 2276 if (!strcmp(mountlist->el[lino].mountpoint, "swap")) { 2277 sprintf(command, "swapoff %s", mountlist->el[lino].device); 2278 } else { 2279 if (!strcmp(mountlist->el[lino].mountpoint, "/1")) { 2280 sprintf(command, "umount %s/", MNT_RESTORING); 2281 log_msg(3, 2282 "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight..."); 2283 } else { 2284 sprintf(command, "umount " MNT_RESTORING "%s", 2285 mountlist->el[lino].mountpoint); 2286 } 2287 } 2288 log_msg(10, "The 'umount' command is '%s'", command); 2289 res = run_program_and_log_output(command, 3); 2290 } else { 2291 strcat(tmp, "...not mounted anyway :-) OK"); 2292 res = 0; 2293 } 2294 g_current_progress++; 2295 if (res) { 2296 strcat(tmp, "...Failed"); 2297 retval++; 2298 log_to_screen(tmp); 2299 } else { 2300 log_msg(2, tmp); 2301 } 2302 } 2303 close_progress_form(); 2304 if (retval) { 2305 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 2306 } else { 2307 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2308 } 2309 if (retval) { 2310 log_to_screen("Unable to unmount some of your partitions."); 2311 } else { 2312 log_to_screen("All partitions were unmounted OK."); 2313 } 2314 free(mountlist); 2315 paranoid_free(command); 2316 paranoid_free(tmp); 2317 return (retval); 2318 } 2319 2383 2320 /************************************************************************** 2384 2321 *END_UNMOUNT_ALL_DEVICES * … … 2393 2330 * @return 0 for success, nonzero for failure. 2394 2331 */ 2395 int extract_cfg_file_and_mountlist_from_tape_dev(char*dev) 2396 { 2397 char *command; 2398 int res=0; 2399 // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0 2400 long tape_block_size=32768; 2401 2402 malloc_string(command); 2403 2404 // tar -zxvf- 2405 sprintf( command, 2406 "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s", 2407 dev, 2408 tape_block_size, 2409 1024L*1024*32/tape_block_size, 2410 MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, 2411 BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, 2412 "tmp/i-want-my-lvm" ); 2413 log_msg (2, "command = '%s'", command); 2414 res = run_program_and_log_output( command, -1 ); 2415 if (res!=0 && does_file_exist(MONDO_CFG_FILE_STUB)) { res=0; } 2416 paranoid_free(command); 2417 return(res); 2418 } 2419 2420 2421 2332 int extract_cfg_file_and_mountlist_from_tape_dev(char *dev) 2333 { 2334 char *command; 2335 int res = 0; 2336 // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0 2337 long tape_block_size = 32768; 2338 2339 malloc_string(command); 2340 2341 // tar -zxvf- 2342 sprintf(command, 2343 "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s", 2344 dev, 2345 tape_block_size, 2346 1024L * 1024 * 32 / tape_block_size, 2347 MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, 2348 BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm"); 2349 log_msg(2, "command = '%s'", command); 2350 res = run_program_and_log_output(command, -1); 2351 if (res != 0 && does_file_exist(MONDO_CFG_FILE_STUB)) { 2352 res = 0; 2353 } 2354 paranoid_free(command); 2355 return (res); 2356 } 2357 2358 2359 2422 2360 /** 2423 2361 * Get the configuration file from the floppy, tape, or CD. … … 2428 2366 * @return 0 for success, nonzero for failure. 2429 2367 */ 2430 int 2431 get_cfg_file_from_archive( struct s_bkpinfo *bkpinfo ) 2432 { 2433 int retval = 0; 2434 2368 int get_cfg_file_from_archive(struct s_bkpinfo *bkpinfo) 2369 { 2370 int retval = 0; 2371 2435 2372 /** malloc *****/ 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 assert(bkpinfo!=NULL);2449 2450 2451 2452 2453 2454 2455 2456 2457 log_msg(2, "gcffa --- starting");2458 2459 sprintf( mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);2460 2461 chdir( bkpinfo->tmpdir);2462 strcpy(cfg_file, MONDO_CFG_FILE_STUB);2463 unlink( cfg_file );// cfg_file[] is missing the '/' at the start, FYI, by intent2464 unlink( FILELIST_FULL_STUB);2465 unlink( BIGGIELIST_TXT_STUB);2466 unlink("tmp/i-want-my-lvm");2467 sprintf( command, "mkdir -p %s", mountpt);2468 run_program_and_log_output( command, FALSE);2469 2373 char *device; 2374 char *command; 2375 char *cfg_file; 2376 char *mounted_cfgf_path; 2377 char *tmp; 2378 char *mountpt; 2379 char *ramdisk_fname; 2380 char *mountlist_file; 2381 int res; 2382 2383 bool try_plan_B; 2384 2385 assert(bkpinfo != NULL); 2386 malloc_string(cfg_file); 2387 malloc_string(mounted_cfgf_path); 2388 malloc_string(mountpt); 2389 malloc_string(ramdisk_fname); 2390 malloc_string(mountlist_file); 2391 malloc_string(device); 2392 malloc_string(command); 2393 malloc_string(tmp); 2394 log_msg(2, "gcffa --- starting"); 2395 log_to_screen("I'm thinking..."); 2396 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir); 2397 device[0] = '\0'; 2398 chdir(bkpinfo->tmpdir); 2399 strcpy(cfg_file, MONDO_CFG_FILE_STUB); 2400 unlink(cfg_file); // cfg_file[] is missing the '/' at the start, FYI, by intent 2401 unlink(FILELIST_FULL_STUB); 2402 unlink(BIGGIELIST_TXT_STUB); 2403 unlink("tmp/i-want-my-lvm"); 2404 sprintf(command, "mkdir -p %s", mountpt); 2405 run_program_and_log_output(command, FALSE); 2406 2470 2407 // unlink( "tmp/mondo-restore.cfg" ); // superfluous, surely? 2471 2472 sprintf( cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB ); 2473 sprintf( mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB ); 2474 // make_hole_for_file( cfg_file ); 2475 // make_hole_for_file( mountlist_file); 2476 log_msg (2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file ); 2477 2478 /* Floppy? */ 2479 sprintf( tmp, "mkdir -p %s", mountpt ); 2480 run_program_and_log_output( tmp, FALSE ); 2481 sprintf( tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir); 2482 run_program_and_log_output( tmp, FALSE); 2483 2484 sprintf( command, "mount /dev/fd0u1722 %s", mountpt ); 2485 sprintf( tmp, "(sleep 15; kill `ps ax | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &", command); 2486 log_msg(1, "tmp = '%s'", tmp); 2487 system(tmp); 2488 res = run_program_and_log_output( command, FALSE ); 2489 if (res) { 2490 sprintf( command, "mount /dev/fd0H1440 %s", mountpt ); 2491 res = run_program_and_log_output( command, FALSE ); 2492 } 2493 if (res) { 2494 try_plan_B=TRUE; 2495 } else { 2496 try_plan_B=TRUE; 2497 log_msg(2, "Mounted floppy OK but I don't trust it because the archives might contain more up-to-date config file than the floppy does."); 2408 2409 sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB); 2410 sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, 2411 MOUNTLIST_FNAME_STUB); 2412 // make_hole_for_file( cfg_file ); 2413 // make_hole_for_file( mountlist_file); 2414 log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file); 2415 2416 /* Floppy? */ 2417 sprintf(tmp, "mkdir -p %s", mountpt); 2418 run_program_and_log_output(tmp, FALSE); 2419 sprintf(tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir); 2420 run_program_and_log_output(tmp, FALSE); 2421 2422 sprintf(command, "mount /dev/fd0u1722 %s", mountpt); 2423 sprintf(tmp, 2424 "(sleep 15; kill `ps ax | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &", 2425 command); 2426 log_msg(1, "tmp = '%s'", tmp); 2427 system(tmp); 2428 res = run_program_and_log_output(command, FALSE); 2429 if (res) { 2430 sprintf(command, "mount /dev/fd0H1440 %s", mountpt); 2431 res = run_program_and_log_output(command, FALSE); 2432 } 2433 if (res) { 2434 try_plan_B = TRUE; 2435 } else { 2436 try_plan_B = TRUE; 2437 log_msg(2, 2438 "Mounted floppy OK but I don't trust it because the archives might contain more up-to-date config file than the floppy does."); 2498 2439 // NB: If busybox does not support 'mount -o loop' then Plan A WILL NOT WORK. 2499 log_msg(2, "Processing floppy (plan A?)" ); 2500 sprintf( ramdisk_fname, "%s/mindi.rdz", mountpt ); 2501 if ( !does_file_exist( ramdisk_fname ) ) 2502 { 2503 sprintf( ramdisk_fname, "%s/initrd.img", mountpt ); 2504 } 2505 if ( !does_file_exist( ramdisk_fname ) ) 2506 { 2507 log_msg(2, "Cannot find ramdisk file on mountpoint. Are you sure that's a boot disk in the drive?" ); 2508 } 2509 if ( extract_config_file_from_ramdisk( bkpinfo, ramdisk_fname, cfg_file, mountlist_file ) ) 2510 { 2511 log_msg(2, "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled." ); 2512 } 2513 sprintf( command, "umount %s", mountpt ); 2514 run_program_and_log_output(command, 5); 2515 unlink(ramdisk_fname); 2516 } 2517 if ( !does_file_exist( cfg_file ) ) 2518 { 2519 log_msg(2, "gcffa --- we don't have cfg file yet." ); 2520 if ( IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ) 2521 { 2522 try_plan_B = TRUE; 2523 } 2524 else 2525 { 2526 log_msg(2, "gcffa --- calling mount_cdrom now :)" ); 2527 if ( !mount_cdrom( bkpinfo ) ) 2528 { 2529 log_msg(2, "gcffa --- managed to mount CD; so, no need for Plan B" ); 2530 try_plan_B = FALSE; 2531 } 2532 else 2533 { 2534 try_plan_B = TRUE; 2535 } 2536 if ( what_number_cd_is_this(bkpinfo) > 1 ) 2537 { 2538 insist_on_this_cd_number( bkpinfo, ( g_current_media_number = 1 ) ); 2539 } 2540 } 2541 if ( try_plan_B ) 2542 { 2543 log_msg(2, "gcffa --- OK, switching to Plan B" ); 2544 chdir( bkpinfo->tmpdir ); 2545 run_program_and_log_output ( "mkdir -p tmp", FALSE ); 2546 2547 if (strlen(bkpinfo->media_device) ==0 ) 2548 { 2549 strcpy(bkpinfo->media_device, "/dev/st0"); 2550 log_msg(2,"media_device is blank; assuming %s"); 2551 } 2552 strcpy(tmp, bkpinfo->media_device); 2553 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) 2554 { 2555 strcpy(bkpinfo->media_device, "/dev/st0"); 2556 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) 2557 { 2558 strcpy(bkpinfo->media_device, "/dev/osst0"); 2559 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) 2560 { 2561 strcpy(bkpinfo->media_device, "/dev/ht0"); 2562 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) 2563 { 2564 log_msg(3, "I tried lots of devices but none worked."); 2565 strcpy(bkpinfo->media_device, tmp); 2566 } 2567 } 2568 } 2569 } 2570 2571 if ( !does_file_exist( "tmp/mondo-restore.cfg") ) 2572 { 2573 log_to_screen ( "Cannot find config info on tape/CD/floppy"); 2574 return(1); 2575 } 2576 } 2577 else 2578 { 2579 log_msg(2, "gcffa --- looking at mounted CD for mindi-boot.2880.img" ); 2580 sprintf( command, "mount "MNT_CDROM"/images/mindi-boot.2880.img -o loop %s", mountpt ); 2581 sprintf( mounted_cfgf_path, "%s/%s", mountpt, cfg_file ); 2582 if (!does_file_exist(mounted_cfgf_path)) 2583 { 2584 log_msg(2,"gcffa --- Plan C, a.k.a. untarring some file from all.tar.gz" ); 2585 sprintf( command, 2586 "tar -zxvf "MNT_CDROM"/images/all.tar.gz %s %s %s %s %s", 2587 MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm" 2588 ); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary 2589 run_program_and_log_output( command, TRUE ); 2590 if ( !does_file_exist( MONDO_CFG_FILE_STUB ) ) 2591 { 2592 fatal_error( "Please reinsert the disk/CD and try again." ); 2593 } 2594 } 2595 } 2596 } 2597 if ( does_file_exist( MONDO_CFG_FILE_STUB) ) 2598 { 2599 log_msg(1, "gcffa --- great! We've got the config file" ); 2600 sprintf(tmp, "%s/%s", call_program_and_get_last_line_of_output("pwd"), MONDO_CFG_FILE_STUB); 2601 sprintf( command, "cp -f %s %s", tmp, cfg_file); 2602 iamhere(command); 2603 if (strcmp(tmp, cfg_file) && run_program_and_log_output( command, 1 )) 2604 { log_msg(1,"... but an error occurred when I tried to move it to %s", cfg_file); } 2605 else 2606 { log_msg(1,"... and I moved it successfully to %s", cfg_file); } 2607 sprintf(command, "cp -f %s/%s %s", call_program_and_get_last_line_of_output("pwd"), MOUNTLIST_FNAME_STUB, mountlist_file); 2608 iamhere(command); 2609 if (strcmp(tmp, cfg_file) && run_program_and_log_output( command, 1 )) 2610 { log_msg(1,"Failed to get mountlist"); } 2611 else 2612 { 2613 log_msg(1,"Got mountlist too"); 2614 sprintf(command, "cp -f %s %s", mountlist_file, g_mountlist_fname); 2615 if (run_program_and_log_output(command, 1)) 2616 { log_msg(1, "Failed to copy mountlist to /tmp"); } 2617 else 2618 { 2619 log_msg(1, "Copied mountlist to /tmp as well OK"); 2620 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/"); 2621 run_program_and_log_output(command, 1); 2440 log_msg(2, "Processing floppy (plan A?)"); 2441 sprintf(ramdisk_fname, "%s/mindi.rdz", mountpt); 2442 if (!does_file_exist(ramdisk_fname)) { 2443 sprintf(ramdisk_fname, "%s/initrd.img", mountpt); 2444 } 2445 if (!does_file_exist(ramdisk_fname)) { 2446 log_msg(2, 2447 "Cannot find ramdisk file on mountpoint. Are you sure that's a boot disk in the drive?"); 2448 } 2449 if (extract_config_file_from_ramdisk 2450 (bkpinfo, ramdisk_fname, cfg_file, mountlist_file)) { 2451 log_msg(2, 2452 "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled."); 2453 } 2454 sprintf(command, "umount %s", mountpt); 2455 run_program_and_log_output(command, 5); 2456 unlink(ramdisk_fname); 2457 } 2458 if (!does_file_exist(cfg_file)) { 2459 log_msg(2, "gcffa --- we don't have cfg file yet."); 2460 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 2461 try_plan_B = TRUE; 2462 } else { 2463 log_msg(2, "gcffa --- calling mount_cdrom now :)"); 2464 if (!mount_cdrom(bkpinfo)) { 2465 log_msg(2, 2466 "gcffa --- managed to mount CD; so, no need for Plan B"); 2467 try_plan_B = FALSE; 2468 } else { 2469 try_plan_B = TRUE; 2470 } 2471 if (what_number_cd_is_this(bkpinfo) > 1) { 2472 insist_on_this_cd_number(bkpinfo, 2473 (g_current_media_number = 1)); 2474 } 2475 } 2476 if (try_plan_B) { 2477 log_msg(2, "gcffa --- OK, switching to Plan B"); 2478 chdir(bkpinfo->tmpdir); 2479 run_program_and_log_output("mkdir -p tmp", FALSE); 2480 2481 if (strlen(bkpinfo->media_device) == 0) { 2482 strcpy(bkpinfo->media_device, "/dev/st0"); 2483 log_msg(2, "media_device is blank; assuming %s"); 2484 } 2485 strcpy(tmp, bkpinfo->media_device); 2486 if (extract_cfg_file_and_mountlist_from_tape_dev 2487 (bkpinfo->media_device)) { 2488 strcpy(bkpinfo->media_device, "/dev/st0"); 2489 if (extract_cfg_file_and_mountlist_from_tape_dev 2490 (bkpinfo->media_device)) { 2491 strcpy(bkpinfo->media_device, "/dev/osst0"); 2492 if (extract_cfg_file_and_mountlist_from_tape_dev 2493 (bkpinfo->media_device)) { 2494 strcpy(bkpinfo->media_device, "/dev/ht0"); 2495 if (extract_cfg_file_and_mountlist_from_tape_dev 2496 (bkpinfo->media_device)) { 2497 log_msg(3, 2498 "I tried lots of devices but none worked."); 2499 strcpy(bkpinfo->media_device, tmp); 2500 } 2501 } 2502 } 2503 } 2504 2505 if (!does_file_exist("tmp/mondo-restore.cfg")) { 2506 log_to_screen("Cannot find config info on tape/CD/floppy"); 2507 return (1); 2508 } 2509 } else { 2510 log_msg(2, 2511 "gcffa --- looking at mounted CD for mindi-boot.2880.img"); 2512 sprintf(command, 2513 "mount " MNT_CDROM 2514 "/images/mindi-boot.2880.img -o loop %s", mountpt); 2515 sprintf(mounted_cfgf_path, "%s/%s", mountpt, cfg_file); 2516 if (!does_file_exist(mounted_cfgf_path)) { 2517 log_msg(2, 2518 "gcffa --- Plan C, a.k.a. untarring some file from all.tar.gz"); 2519 sprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm"); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary 2520 run_program_and_log_output(command, TRUE); 2521 if (!does_file_exist(MONDO_CFG_FILE_STUB)) { 2522 fatal_error 2523 ("Please reinsert the disk/CD and try again."); 2524 } 2525 } 2526 } 2527 } 2528 if (does_file_exist(MONDO_CFG_FILE_STUB)) { 2529 log_msg(1, "gcffa --- great! We've got the config file"); 2530 sprintf(tmp, "%s/%s", 2531 call_program_and_get_last_line_of_output("pwd"), 2532 MONDO_CFG_FILE_STUB); 2533 sprintf(command, "cp -f %s %s", tmp, cfg_file); 2534 iamhere(command); 2535 if (strcmp(tmp, cfg_file) 2536 && run_program_and_log_output(command, 1)) { 2537 log_msg(1, 2538 "... but an error occurred when I tried to move it to %s", 2539 cfg_file); 2540 } else { 2541 log_msg(1, "... and I moved it successfully to %s", cfg_file); 2542 } 2543 sprintf(command, "cp -f %s/%s %s", 2544 call_program_and_get_last_line_of_output("pwd"), 2545 MOUNTLIST_FNAME_STUB, mountlist_file); 2546 iamhere(command); 2547 if (strcmp(tmp, cfg_file) 2548 && run_program_and_log_output(command, 1)) { 2549 log_msg(1, "Failed to get mountlist"); 2550 } else { 2551 log_msg(1, "Got mountlist too"); 2552 sprintf(command, "cp -f %s %s", mountlist_file, 2553 g_mountlist_fname); 2554 if (run_program_and_log_output(command, 1)) { 2555 log_msg(1, "Failed to copy mountlist to /tmp"); 2556 } else { 2557 log_msg(1, "Copied mountlist to /tmp as well OK"); 2558 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/"); 2559 run_program_and_log_output(command, 1); 2622 2560 /* sprintf(command, "grep \" lvm \" %s", g_mountlist_fname); 2623 2561 if (!run_program_and_log_output(command, 5) && !does_file_exist("/tmp/i-want-my-lvm")) … … 2639 2577 } 2640 2578 */ 2641 } 2642 } 2643 } 2644 run_program_and_log_output( "umount "MNT_CDROM, FALSE ); 2645 if ( !does_file_exist( cfg_file ) ) 2646 { 2647 iamhere(cfg_file); 2648 log_msg(1, "%s not found", cfg_file); 2649 log_to_screen("Oh dear. Unable to recover configuration file from boot disk"); 2650 return(1); 2651 } 2652 2653 log_to_screen( "Recovered mondo-restore.cfg" ); 2654 if (!does_file_exist( MOUNTLIST_FNAME_STUB )) 2655 { log_to_screen( "...but not mountlist.txt - a pity, really..."); } 2579 } 2580 } 2581 } 2582 run_program_and_log_output("umount " MNT_CDROM, FALSE); 2583 if (!does_file_exist(cfg_file)) { 2584 iamhere(cfg_file); 2585 log_msg(1, "%s not found", cfg_file); 2586 log_to_screen 2587 ("Oh dear. Unable to recover configuration file from boot disk"); 2588 return (1); 2589 } 2590 2591 log_to_screen("Recovered mondo-restore.cfg"); 2592 if (!does_file_exist(MOUNTLIST_FNAME_STUB)) { 2593 log_to_screen("...but not mountlist.txt - a pity, really..."); 2594 } 2656 2595 /* start SAH */ 2657 else 2658 { 2659 sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);2660 run_program_and_log_output(command,FALSE);2661 2596 else { 2597 sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB, 2598 bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB); 2599 run_program_and_log_output(command, FALSE); 2600 } 2662 2601 /*--commented out by SAH 2663 2602 sprintf( command, "cp -f %s %s/%s", cfg_file, bkpinfo->tmpdir, MONDO_CFG_FILE_STUB ); … … 2668 2607 /* end SAH */ 2669 2608 2670 sprintf( command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);2671 run_program_and_log_output( command, FALSE);2672 sprintf( command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);2673 run_program_and_log_output( command, FALSE);2674 sprintf(command, "cp -f etc/raidtab /etc/");2675 run_program_and_log_output( command, FALSE);2676 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");2677 run_program_and_log_output( command, FALSE);2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 return( retval);2609 sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB); 2610 run_program_and_log_output(command, FALSE); 2611 sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB); 2612 run_program_and_log_output(command, FALSE); 2613 sprintf(command, "cp -f etc/raidtab /etc/"); 2614 run_program_and_log_output(command, FALSE); 2615 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/"); 2616 run_program_and_log_output(command, FALSE); 2617 g_backup_media_type = bkpinfo->backup_media_type; 2618 paranoid_free(device); 2619 paranoid_free(command); 2620 paranoid_free(tmp); 2621 paranoid_free(cfg_file); 2622 paranoid_free(mounted_cfgf_path); 2623 paranoid_free(mountpt); 2624 paranoid_free(ramdisk_fname); 2625 paranoid_free(mountlist_file); 2626 return (retval); 2688 2627 } 2689 2628 … … 2706 2645 ***************************************************************************/ 2707 2646 2708 2709 2710 void wait_until_software_raids_are_prepped(char *mdstat_file, int wait_for_percentage)2711 { 2712 struct s_mdstat *mdstat; 2713 int unfinished_mdstat_devices=9999, i;2714 char *screen_message;2715 2716 malloc_string(screen_message); 2717 mdstat = malloc(sizeof(struct s_mdstat));2718 2719 assert(wait_for_percentage <= 100); 2720 iamhere("Help, my boat is sync'ing. (Get it? Urp! Urp!)");2721 while(unfinished_mdstat_devices > 0) 2722 2723 if (read_mdstat(mdstat, mdstat_file)) 2724 { log_to_screen("Sorry, cannot read %s", mdstat_file); return; } 2725 for(unfinished_mdstat_devices=i=0; i<mdstat->entries; i++) 2726 { 2727 if (mdstat->el[i].progress < wait_for_percentage) 2728 2729 2730 sprintf(screen_message, "Sync'ing /dev/md%d", mdstat->el[i].md);2731 open_evalcall_form(screen_message);2732 if (mdstat->el[i].progress == -1) // delayed while another partition inits2733 {2734 continue;2735 }2736 while(mdstat->el[i].progress < wait_for_percentage)2737 2738 2739 2740 if (read_mdstat(mdstat, mdstat_file)) {break;}2741 }2742 close_evalcall_form();2743 2744 } 2745 2746 paranoid_free(screen_message); 2747 paranoid_free(mdstat); 2748 } 2749 2750 2647 2648 2649 void wait_until_software_raids_are_prepped(char *mdstat_file, 2650 int wait_for_percentage) 2651 { 2652 struct s_mdstat *mdstat; 2653 int unfinished_mdstat_devices = 9999, i; 2654 char *screen_message; 2655 2656 malloc_string(screen_message); 2657 mdstat = malloc(sizeof(struct s_mdstat)); 2658 2659 assert(wait_for_percentage <= 100); 2660 iamhere("Help, my boat is sync'ing. (Get it? Urp! Urp!)"); 2661 while (unfinished_mdstat_devices > 0) { 2662 if (read_mdstat(mdstat, mdstat_file)) { 2663 log_to_screen("Sorry, cannot read %s", mdstat_file); 2664 return; 2665 } 2666 for (unfinished_mdstat_devices = i = 0; i < mdstat->entries; i++) { 2667 if (mdstat->el[i].progress < wait_for_percentage) { 2668 unfinished_mdstat_devices++; 2669 sprintf(screen_message, "Sync'ing /dev/md%d", 2670 mdstat->el[i].md); 2671 open_evalcall_form(screen_message); 2672 if (mdstat->el[i].progress == -1) // delayed while another partition inits 2673 { 2674 continue; 2675 } 2676 while (mdstat->el[i].progress < wait_for_percentage) { 2677 update_evalcall_form(mdstat->el[i].progress); 2678 sleep(2); 2679 if (read_mdstat(mdstat, mdstat_file)) { 2680 break; 2681 } 2682 } 2683 close_evalcall_form(); 2684 } 2685 } 2686 } 2687 paranoid_free(screen_message); 2688 paranoid_free(mdstat); 2689 } -
trunk/mondo/mondo/mondorestore/mondo-rstr-tools.h
r30 r59 4 4 5 5 void free_global_filenames(); 6 void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *);7 bool is_file_in_list(char *, char*, char*);/* needle, haystack, preamble */6 void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *); 7 bool is_file_in_list(char *, char *, char *); /* needle, haystack, preamble */ 8 8 int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please); 9 9 void kill_petris(void); 10 int modify_rclocal_one_time( char *path);10 int modify_rclocal_one_time(char *path); 11 11 int mount_cdrom(struct s_bkpinfo *bkpinfo); 12 int mount_device(char *,char*,char*,bool);13 int mount_all_devices(struct mountlist_itself *, bool);12 int mount_device(char *, char *, char *, bool); 13 int mount_all_devices(struct mountlist_itself *, bool); 14 14 void protect_against_braindead_sysadmins(void); 15 int read_cfg_file_into_bkpinfo( char*cfg_file, struct s_bkpinfo *bkpinfo);15 int read_cfg_file_into_bkpinfo(char *cfg_file, struct s_bkpinfo *bkpinfo); 16 16 struct s_node *process_filelist_and_biggielist(struct s_bkpinfo *); 17 int backup_crucial_file(char *path_root, char *filename);17 int backup_crucial_file(char *path_root, char *filename); 18 18 19 19 int run_boot_loader(bool); 20 int run_grub(bool, char *);20 int run_grub(bool, char *); 21 21 int run_lilo(bool); 22 22 int run_elilo(bool); 23 23 int run_raw_mbr(bool offer_to_hack_scripts, char *bd); 24 24 char *find_my_editor(void); 25 void streamline_changes_file(char *,char*);26 void set_signals( int on);25 void streamline_changes_file(char *, char *); 26 void set_signals(int on); 27 27 void setup_global_filenames(struct s_bkpinfo *bkpinfo); 28 28 //void setup_signals(int); 29 29 void success_message(void); 30 30 void twenty_seconds_til_yikes(void); 31 int run_raw_mbr(bool offer_to_hack_scripts, char *bd);31 int run_raw_mbr(bool offer_to_hack_scripts, char *bd); 32 32 void terminate_daemon(int); 33 33 void termination_in_progress(int); 34 int unmount_all_devices(struct mountlist_itself *);34 int unmount_all_devices(struct mountlist_itself *); 35 35 int get_cfg_file_from_archive(struct s_bkpinfo *bkpinfo); 36 void ask_about_these_imagedevs( char *infname, char *outfname ); 37 36 void ask_about_these_imagedevs(char *infname, char *outfname); -
trunk/mondo/mondo/mondorestore/mondoprep.h
r30 r59 5 5 copyright : (C) 2002 by Stan Benoit 6 6 email : troff@nakedsoul.org 7 cvsid : $Id : mondoprep.h,v 1.4 2004/06/16 10:38:29 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 23 23 extern int g_currentY, g_current_cd_number; 24 24 extern char *g_tape_device; 25 extern void finish 26 extern void setup_newt_stuff 27 extern char which_restore_mode 28 extern bool ask_me_yes_or_no 29 extern long get_phys_size_of_drive 25 extern void finish(int); 26 extern void setup_newt_stuff(void); 27 extern char which_restore_mode(void); 28 extern bool ask_me_yes_or_no(char *); 29 extern long get_phys_size_of_drive(char *); 30 30 //extern void log_to_screen (char *); 31 extern void update_progress_form 32 extern void open_progress_form 33 extern void close_progress_form 34 extern void popup_and_OK 35 extern bool popup_and_get_string 36 extern long get_time 37 extern bool is_this_device_mounted 38 extern int does_partition_exist 39 extern int strcmp_inc_numbers 40 extern long count_lines_in_file 41 extern long long length_of_file 42 extern long noof_lines_that_match_wildcard 31 extern void update_progress_form(char *); 32 extern void open_progress_form(char *, char *, char *, char *, long); 33 extern void close_progress_form(void); 34 extern void popup_and_OK(char *); 35 extern bool popup_and_get_string(char *, char *, char *, int); 36 extern long get_time(void); 37 extern bool is_this_device_mounted(char *); 38 extern int does_partition_exist(const char *device, int partno); 39 extern int strcmp_inc_numbers(char *, char *); 40 extern long count_lines_in_file(char *); 41 extern long long length_of_file(char *); 42 extern long noof_lines_that_match_wildcard(char *, char *); 43 43 //extern char *slice_fname (long, long, bool, char *); 44 extern char *last_line_of_file 45 extern void log_file_end_to_screen 46 extern int zero_out_a_device 47 extern void mvaddstr_and_log_it 48 extern bool does_file_exist 44 extern char *last_line_of_file(char *); 45 extern void log_file_end_to_screen(char *, char *); 46 extern int zero_out_a_device(char *); 47 extern void mvaddstr_and_log_it(int, int, char *); 48 extern bool does_file_exist(char *); 49 49 50 50 51 51 /** locals **********************************************************/ 52 int extrapolate_mountlist_to_include_raid_partitions (struct mountlist_itself 53 *, 54 struct mountlist_itself 55 *); 56 bool mountlist_contains_raid_devices (struct mountlist_itself *); 57 int start_raid_device (char *); 58 int stop_raid_device (char *); 59 int start_all_raid_devices (struct mountlist_itself *); 60 int stop_all_raid_devices (struct mountlist_itself *); 61 int format_everything (struct mountlist_itself *, bool); 62 int partition_device (FILE*,const char *, int, int, const char *, long long); 63 int partition_device_with_parted (FILE*,const char *, int, int, const char *, long long); 64 int partition_device_with_fdisk (FILE*,const char *, int, int, const char *, long long); 65 int format_device (char *, char *); 66 int partition_drive (struct mountlist_itself *, char *); 67 int partition_everything (struct mountlist_itself *); 68 int do_my_funky_lvm_stuff (bool, bool); 69 int which_format_command_do_i_need (char *, char *); 70 int make_dummy_partitions (FILE*, char *, int); 71 int make_list_of_drives (struct mountlist_itself *, 72 char drivelist[ARBITRARY_MAXIMUM][MAX_STR_LEN]); 73 int set_partition_type (FILE*,const char *, int, const char *, long long); 74 void resize_drive_proportionately_to_suit_new_drives (struct mountlist_itself 75 *mountlist, 76 char *drive_name); 77 void resize_mountlist_proportionately_to_suit_new_drives (struct 78 mountlist_itself 79 *mountlist); 52 int extrapolate_mountlist_to_include_raid_partitions(struct mountlist_itself 53 *, struct mountlist_itself 54 *); 55 bool mountlist_contains_raid_devices(struct mountlist_itself *); 56 int start_raid_device(char *); 57 int stop_raid_device(char *); 58 int start_all_raid_devices(struct mountlist_itself *); 59 int stop_all_raid_devices(struct mountlist_itself *); 60 int format_everything(struct mountlist_itself *, bool); 61 int partition_device(FILE *, const char *, int, int, const char *, 62 long long); 63 int partition_device_with_parted(FILE *, const char *, int, int, 64 const char *, long long); 65 int partition_device_with_fdisk(FILE *, const char *, int, int, 66 const char *, long long); 67 int format_device(char *, char *); 68 int partition_drive(struct mountlist_itself *, char *); 69 int partition_everything(struct mountlist_itself *); 70 int do_my_funky_lvm_stuff(bool, bool); 71 int which_format_command_do_i_need(char *, char *); 72 int make_dummy_partitions(FILE *, char *, int); 73 int make_list_of_drives(struct mountlist_itself *, 74 char drivelist[ARBITRARY_MAXIMUM][MAX_STR_LEN]); 75 int set_partition_type(FILE *, const char *, int, const char *, long long); 76 void resize_drive_proportionately_to_suit_new_drives(struct mountlist_itself 77 *mountlist, 78 char *drive_name); 79 void resize_mountlist_proportionately_to_suit_new_drives(struct 80 mountlist_itself 81 *mountlist); 80 82 81 83 82 char * 83 truncate_to_drive_name (char *partition); 84 void create_mountlist_for_drive(struct mountlist_itself *mountlist, char *drive_name, struct mountlist_reference *drivemntlist); 85 84 char *truncate_to_drive_name(char *partition); 85 void create_mountlist_for_drive(struct mountlist_itself *mountlist, 86 char *drive_name, 87 struct mountlist_reference *drivemntlist); -
trunk/mondo/mondo/mondorestore/mr-externs.h
r30 r59 1 1 /* 2 * $Id : mr-externs.h,v 1.3 2004/06/10 15:29:13 hugo Exp$2 * $Id$ 3 3 * 4 4 * mondo-restore.c's externs … … 6 6 */ 7 7 8 #define SIZE 730000 * 1024 8 #define SIZE 730000 * 1024 /* Size for ISO's stops -1 */ 9 9 #define BIGGIELIST MNT_CDROM"/archives/biggielist.txt" 10 10 #define ARCHIVES_PATH MNT_CDROM"/archives" … … 14 14 #endif 15 15 16 extern bool ask_me_yes_or_no(char *);17 extern char * calc_checksum_of_file(char*);18 extern int closein_tape(struct s_bkpinfo *);16 extern bool ask_me_yes_or_no(char *); 17 extern char *calc_checksum_of_file(char *); 18 extern int closein_tape(struct s_bkpinfo *); 19 19 extern void close_evalcall_form(void); 20 extern char *call_program_and_get_last_line_of_output(char *);20 extern char *call_program_and_get_last_line_of_output(char *); 21 21 extern void close_progress_form(void); 22 extern long count_lines_in_file(char *);23 extern bool does_file_exist(char *);24 extern int does_partition_exist(const char *device, int partno);22 extern long count_lines_in_file(char *); 23 extern bool does_file_exist(char *); 24 extern int does_partition_exist(const char *device, int partno); 25 25 extern int do_my_funky_lvm_stuff(bool, bool); 26 26 extern int edit_filelist(struct s_node *); 27 extern int edit_mountlist(char* mountlist_fname, struct mountlist_itself*, struct raidlist_itself*); 28 extern int format_everything(struct mountlist_itself*, bool); 29 extern int format_device(char*,char*); 27 extern int edit_mountlist(char *mountlist_fname, struct mountlist_itself *, 28 struct raidlist_itself *); 29 extern int format_everything(struct mountlist_itself *, bool); 30 extern int format_device(char *, char *); 30 31 extern void finish(int); 31 extern void free_filelist(struct s_node *);32 extern void free_filelist(struct s_node *); 32 33 extern long get_time(void); 33 extern bool get_isodir_info(char *,char*,char*,bool);34 extern void fatal_error(char *);35 extern void initialize_raid_record(struct raid_device_record *);36 extern bool is_this_device_mounted(char *);37 extern long long length_of_file(char *);38 extern char *last_line_of_file(char *);39 extern struct s_node *load_filelist(char *);34 extern bool get_isodir_info(char *, char *, char *, bool); 35 extern void fatal_error(char *); 36 extern void initialize_raid_record(struct raid_device_record *); 37 extern bool is_this_device_mounted(char *); 38 extern long long length_of_file(char *); 39 extern char *last_line_of_file(char *); 40 extern struct s_node *load_filelist(char *); 40 41 extern void log_tape_pos(void); 41 extern void initialize_raidrec(struct raid_device_record *);42 extern void log_file_end_to_screen(char *,char*);43 extern void log_to_screen 42 extern void initialize_raidrec(struct raid_device_record *); 43 extern void log_file_end_to_screen(char *, char *); 44 extern void log_to_screen(const char *fmt, ...); 44 45 extern void mvaddstr_and_log_it(int, int, char *); 45 extern int make_dummy_partitions(char*,int); 46 extern int make_hole_for_file(char*); 47 extern int make_list_of_drives(struct mountlist_itself*, struct list_of_disks*); 48 extern bool mountlist_contains_raid_devices(struct mountlist_itself*); 49 extern void open_evalcall_form(char*); 50 extern void open_progress_form(char*,char*,char*,char*,long); 46 extern int make_dummy_partitions(char *, int); 47 extern int make_hole_for_file(char *); 48 extern int make_list_of_drives(struct mountlist_itself *, 49 struct list_of_disks *); 50 extern bool mountlist_contains_raid_devices(struct mountlist_itself *); 51 extern void open_evalcall_form(char *); 52 extern void open_progress_form(char *, char *, char *, char *, long); 51 53 extern int openin_cdstream(struct s_bkpinfo *); 52 54 extern int openin_tape(struct s_bkpinfo *); 53 extern int partition_device(char *,int,int,char*,long);54 extern int partition_device_with_fdisk(char *,int,int,char*,long);55 extern int partition_device_with_parted(char *,int,int,char*,long);56 extern int partition_drive(struct mountlist_itself *, char*);57 extern int partition_everything(struct mountlist_itself *);58 extern void popup_and_OK(char *);59 extern bool popup_and_get_string(char *,char*,char*, int);55 extern int partition_device(char *, int, int, char *, long); 56 extern int partition_device_with_fdisk(char *, int, int, char *, long); 57 extern int partition_device_with_parted(char *, int, int, char *, long); 58 extern int partition_drive(struct mountlist_itself *, char *); 59 extern int partition_everything(struct mountlist_itself *); 60 extern void popup_and_OK(char *); 61 extern bool popup_and_get_string(char *, char *, char *, int); 60 62 extern void setup_newt_stuff(void); 61 extern void reset_bkpinfo(struct s_bkpinfo*); 62 extern int read_cfg_var(char*, char*, char*); 63 extern int read_file_from_stream_to_file(struct s_bkpinfo*, char*, long long); 64 extern int read_file_from_stream_to_stream(struct s_bkpinfo*, FILE*, long long); 65 extern int read_file_from_stream_FULL(struct s_bkpinfo*, char*, FILE*, long long); 66 extern int read_header_block_from_stream(long long *, char*, int *); 67 extern void save_filelist(struct s_node*, char*); 68 extern void strip_spaces(char*); 69 extern int strcmp_inc_numbers(char*,char*); 70 extern char *slice_fname(long,long,char*,char*); 71 extern int stop_raid_device(char*); 72 extern int stop_all_raid_devices(struct mountlist_itself*); 63 extern void reset_bkpinfo(struct s_bkpinfo *); 64 extern int read_cfg_var(char *, char *, char *); 65 extern int read_file_from_stream_to_file(struct s_bkpinfo *, char *, 66 long long); 67 extern int read_file_from_stream_to_stream(struct s_bkpinfo *, FILE *, 68 long long); 69 extern int read_file_from_stream_FULL(struct s_bkpinfo *, char *, FILE *, 70 long long); 71 extern int read_header_block_from_stream(long long *, char *, int *); 72 extern void save_filelist(struct s_node *, char *); 73 extern void strip_spaces(char *); 74 extern int strcmp_inc_numbers(char *, char *); 75 extern char *slice_fname(long, long, char *, char *); 76 extern int stop_raid_device(char *); 77 extern int stop_all_raid_devices(struct mountlist_itself *); 73 78 extern void update_evalcall_form(int); 74 extern void update_progress_form(char *);75 extern int verify_tape_backups(struct s_bkpinfo *);79 extern void update_progress_form(char *); 80 extern int verify_tape_backups(struct s_bkpinfo *); 76 81 extern char which_restore_mode(void); 77 extern int which_format_command_do_i_need(char*,char*); 78 extern int write_cfg_var(char*,char*,char*); 79 extern void wrong_marker(int,int); 80 extern void resize_drive_proportionately_to_suit_new_drives(struct mountlist_itself *mountlist, char*drive_name); 81 extern void resize_mountlist_proportionately_to_suit_new_drives(struct mountlist_itself *mountlist); 82 extern int get_cfg_file_from_archive(struct s_bkpinfo*); 82 extern int which_format_command_do_i_need(char *, char *); 83 extern int write_cfg_var(char *, char *, char *); 84 extern void wrong_marker(int, int); 85 extern void resize_drive_proportionately_to_suit_new_drives(struct 86 mountlist_itself 87 *mountlist, 88 char 89 *drive_name); 90 extern void resize_mountlist_proportionately_to_suit_new_drives(struct 91 mountlist_itself 92 *mountlist); 93 extern int get_cfg_file_from_archive(struct s_bkpinfo *); 83 94 84 95 … … 87 98 * Externals yummmy!!! * 88 99 **************************************************************************/ 89 extern long 90 extern long 91 extern long 92 extern int 93 extern int g_current_media_number; /* set to 1 in mondo-tools.c (tape)*/100 extern long g_maximum_progress; 101 extern long g_current_progress; 102 extern long g_start_time; 103 extern int g_currentY; 104 extern int g_current_media_number; /* set to 1 in mondo-tools.c (tape) */ 94 105 extern long long g_tape_posK; 95 106 extern FILE *g_tape_stream; … … 97 108 extern bool g_text_mode; 98 109 extern bool g_restoring_live_from_cd; 99 extern int fput_string_one_char_at_a_time(FILE *, char*);110 extern int fput_string_one_char_at_a_time(FILE *, char *); 100 111 101 112 … … 104 115 105 116 extern int 106 evaluate_mountlist 107 117 evaluate_mountlist(struct mountlist_itself *mountlist, char *flaws_str_A, 118 char *flaws_str_B, char *flaws_str_C); 108 119 109 120 -
trunk/mondo/mondo/xmondo/xmondo.h
r30 r59 5 5 copyright : (C) 2003 by Joshua Oreman 6 6 email : oremanj@get-linux.org 7 cvsid : $Id : xmondo.h,v 1.1 2004/06/10 16:13:06 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 20 20 #define XMONDO_H 21 21 22 #undef scroll 22 #undef scroll // newt weirdness 23 23 24 24 #ifdef HAVE_CONFIG_H … … 41 41 #include "mondostructures.h" 42 42 #undef bool 43 } 44 45 class QVButtonGroup; 43 } class QVButtonGroup; 46 44 class QLabel; 47 45 class QLineEdit; … … 55 53 56 54 /** XMondo is the base class of the project */ 57 class XMondo : public KMainWindow 58 { 59 Q_OBJECT 60 public: 61 /** construtor */ 62 XMondo(QWidget* parent=0, const char *name=0); 63 /** destructor */ 64 virtual ~XMondo(); 55 class XMondo:public KMainWindow { 56 Q_OBJECT public: 57 /** construtor */ 58 XMondo(QWidget * parent = 0, const char *name = 0); 59 /** destructor */ 60 virtual ~ XMondo(); 65 61 66 void fillBkpinfo (struct s_bkpinfo *); 67 68 public slots: 69 void slotVerboseChange (bool v); 70 void slotMode (int x); 71 void slotMediaType (int x); 72 void slotCompareMediaType (int x); 73 void slotRestoreMediaType (int x); 74 void slotStartBackup(); 75 void slotStartCompare(); 76 void slotAddInclude(); 77 void slotAddExclude(); 78 void slotDelInclude(); 79 void slotDelExclude(); 80 void slotTabChange (QWidget *); 81 void slotPrevRestore(); 82 void slotNextRestore(); 83 84 private: 85 void initBackupTab (QWidget *&); 86 void initOptionsTab (QWidget *&); 87 void initAdvancedTab (QWidget *&); 88 void initCompareTab (QWidget *&); 89 void initRestoreTab (QWidget *&); 90 91 QVButtonGroup *buttons; 92 QWidgetStack *stack, *restoreStack; 93 QTabWidget *backup; 94 QWidget *compare, *restore, *tabHardware, *tabOptions, *tabAdvanced, *restoreInfo, *restoreFiles; 95 QPushButton *bStartBackup, *bStartCompare; 96 QPushButton *rPrev, *rNext; 97 QButtonGroup *bgMediaType, *bgCompression, *bgCompareMediaType, *bgCompareCompression, *bgBootLoader, *mainButtons, 98 *bgRestoreMediaType; 99 QLabel *lDOption, *compareLDOption, *nfsRemoteDir, *compareNFSRemoteDir, *restoreLDOption, *restoreNFSRemoteDir; 100 QLineEdit *editDOption, *editMediaSize, *compareEditDOption, *compareEditMediaSize, *restoreEditDOption, 101 *restoreEditMediaSize, *editBootDevice, *editKernel, *editNFSRemoteDir, *compareEditNFSRemoteDir, 102 *restoreEditNFSRemoteDir, *restoreFilter; 103 QListView *listImageDevs, *listInclude, *listExclude, *listExcludeDevs; 104 QCheckBox *checkDifferential, *checkBackupNFS, *checkCompare, 105 *checkMakeBootFloppies, *checkUseLilo; 106 QLineEdit *pendingInclude, *pendingExclude; 107 XMondoBackup *bkup; 108 XMondoRestore *rstr; 62 void fillBkpinfo(struct s_bkpinfo *); 63 64 public slots:void slotVerboseChange(bool v); 65 void slotMode(int x); 66 void slotMediaType(int x); 67 void slotCompareMediaType(int x); 68 void slotRestoreMediaType(int x); 69 void slotStartBackup(); 70 void slotStartCompare(); 71 void slotAddInclude(); 72 void slotAddExclude(); 73 void slotDelInclude(); 74 void slotDelExclude(); 75 void slotTabChange(QWidget *); 76 void slotPrevRestore(); 77 void slotNextRestore(); 78 79 private: 80 void initBackupTab(QWidget * &); 81 void initOptionsTab(QWidget * &); 82 void initAdvancedTab(QWidget * &); 83 void initCompareTab(QWidget * &); 84 void initRestoreTab(QWidget * &); 85 86 QVButtonGroup *buttons; 87 QWidgetStack *stack, *restoreStack; 88 QTabWidget *backup; 89 QWidget *compare, *restore, *tabHardware, *tabOptions, *tabAdvanced, 90 *restoreInfo, *restoreFiles; 91 QPushButton *bStartBackup, *bStartCompare; 92 QPushButton *rPrev, *rNext; 93 QButtonGroup *bgMediaType, *bgCompression, *bgCompareMediaType, 94 *bgCompareCompression, *bgBootLoader, *mainButtons, 95 *bgRestoreMediaType; 96 QLabel *lDOption, *compareLDOption, *nfsRemoteDir, 97 *compareNFSRemoteDir, *restoreLDOption, *restoreNFSRemoteDir; 98 QLineEdit *editDOption, *editMediaSize, *compareEditDOption, 99 *compareEditMediaSize, *restoreEditDOption, *restoreEditMediaSize, 100 *editBootDevice, *editKernel, *editNFSRemoteDir, 101 *compareEditNFSRemoteDir, *restoreEditNFSRemoteDir, *restoreFilter; 102 QListView *listImageDevs, *listInclude, *listExclude, *listExcludeDevs; 103 QCheckBox *checkDifferential, *checkBackupNFS, *checkCompare, 104 *checkMakeBootFloppies, *checkUseLilo; 105 QLineEdit *pendingInclude, *pendingExclude; 106 XMondoBackup *bkup; 107 XMondoRestore *rstr; 109 108 }; 110 109 -
trunk/mondo/mondo/xmondo/xmondobackup.h
r30 r59 5 5 copyright : (C) 2003 by Joshua Oreman 6 6 email : oremanj@get-linux.org 7 cvsid : $Id : xmondobackup.h,v 1.1 2004/06/10 16:13:06 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 28 28 29 29 class BackupThread; 30 class XMondoBackup : public QObject { 31 Q_OBJECT 32 public: 30 class XMondoBackup:public QObject { 31 Q_OBJECT public: 33 32 XMondoBackup(); 34 33 ~XMondoBackup(); 35 int run 36 int compare 34 int run(struct s_bkpinfo *bkpinfo); 35 int compare(struct s_bkpinfo *bkpinfo); 37 36 38 public slots: 39 void abortBackup(); 37 public slots:void abortBackup(); 40 38 41 private:42 BackupThread *th;39 private: 40 BackupThread * th; 43 41 }; 44 42 -
trunk/mondo/mondo/xmondo/xmondorestore.h
r30 r59 5 5 copyright : (C) 2003 by Joshua Oreman 6 6 email : oremanj@get-linux.org 7 cvsid : $Id : xmondorestore.h,v 1.1 2004/06/10 16:13:06 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 32 32 * @author Joshua Oreman 33 33 */ 34 class XMondoRestore : public QObject 35 { 36 Q_OBJECT 34 class XMondoRestore:public QObject { 35 Q_OBJECT friend void *XMondoRestore_preparer_thread(void *arg); 37 36 38 friend void *XMondoRestore_preparer_thread (void *arg);39 40 public: 41 XMondoRestore (QWidget *parent, QButtonGroup *mediaType, QLineEdit *device, QLineEdit *nfsRemoteDir, QLineEdit *filelistFilter);42 virtual ~XMondoRestore();37 public: 38 XMondoRestore(QWidget * parent, QButtonGroup * mediaType, 39 QLineEdit * device, QLineEdit * nfsRemoteDir, 40 QLineEdit * filelistFilter); 41 virtual ~ XMondoRestore(); 43 42 44 virtual void go(); 45 bool good() { 46 return ok; 47 } 48 bool isSetupDone() { 49 return doneSetup; 50 } 43 virtual void go(); 44 bool good() { 45 return ok; 46 } bool isSetupDone() { 47 return doneSetup; 48 } 51 49 52 public slots: 53 void slotAbortRestore(); 50 public slots:void slotAbortRestore(); 54 51 55 protected: 56 bool ok; 57 bool doneSetup; 58 59 QButtonGroup *rMediaType; 60 QLineEdit *rDevice, *rNFSRemoteDir, *rFilter; 52 protected: 53 bool ok; 54 bool doneSetup; 61 55 62 QWidget *files; 63 QLabel *fStatusMsg; 64 QListView *fList; 65 QLabel *fRestoreDirLabel; 66 QLineEdit *fRestoreDir; 56 QButtonGroup *rMediaType; 57 QLineEdit *rDevice, *rNFSRemoteDir, *rFilter; 67 58 68 QString tempdir, filelistLocation, cfgLocation, cdMountpoint; 59 QWidget *files; 60 QLabel *fStatusMsg; 61 QListView *fList; 62 QLabel *fRestoreDirLabel; 63 QLineEdit *fRestoreDir; 69 64 70 pthread_t preparer_thread; 71 72 s_bkpinfo *bkpinfo; 73 74 RestoreThread *th; 65 QString tempdir, filelistLocation, cfgLocation, cdMountpoint; 66 67 pthread_t preparer_thread; 68 69 s_bkpinfo *bkpinfo; 70 71 RestoreThread *th; 75 72 }; 76 73 77 74 #endif 78
Note:
See TracChangeset
for help on using the changeset viewer.