[1] | 1 | /* libmondo-stream.c
|
---|
[128] | 2 | $Id: libmondo-stream.c 1123 2007-02-09 22:41:03Z bruno $
|
---|
[1] | 3 |
|
---|
| 4 | ...tools for talking to tapes, Monitas streams, etc.
|
---|
| 5 |
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | /**
|
---|
| 10 | * @file
|
---|
| 11 | * Functions for writing data to/reading data from streams (tape, CD stream, etc.)
|
---|
| 12 | */
|
---|
| 13 |
|
---|
| 14 | #include "my-stuff.h"
|
---|
[1080] | 15 | #include "mr_mem.h"
|
---|
[1123] | 16 | #include "mr_msg.h"
|
---|
[1] | 17 | #include "mondostructures.h"
|
---|
| 18 | #include "libmondo-devices.h"
|
---|
| 19 | #include "libmondo-stream.h"
|
---|
| 20 | #include "libmondo-string-EXT.h"
|
---|
| 21 | #include "libmondo-files-EXT.h"
|
---|
[541] | 22 | #include "libmondo-gui-EXT.h"
|
---|
[1] | 23 | #include "libmondo-fork-EXT.h"
|
---|
| 24 | #include "libmondo-tools-EXT.h"
|
---|
| 25 | #include "libmondo-fifo-EXT.h"
|
---|
| 26 |
|
---|
| 27 | #define EXTRA_TAPE_CHECKSUMS
|
---|
| 28 |
|
---|
| 29 | /*@unused@*/
|
---|
[128] | 30 | //static char cvsid[] = "$Id: libmondo-stream.c 1123 2007-02-09 22:41:03Z bruno $";
|
---|
[1] | 31 | extern bool g_sigpipe;
|
---|
| 32 | extern int g_tape_buffer_size_MB;
|
---|
| 33 |
|
---|
[948] | 34 | extern char *g_getfacl;
|
---|
| 35 | extern char *g_getfattr;
|
---|
| 36 |
|
---|
[1] | 37 | /**
|
---|
| 38 | * @addtogroup globalGroup
|
---|
| 39 | * @{
|
---|
| 40 | */
|
---|
| 41 | /**
|
---|
| 42 | * The file pointer for the opened tape/CD stream.
|
---|
| 43 | * Opened and closed by openin_tape(), openin_cdstream(),
|
---|
| 44 | * openout_tape(), openout_cdstream(), closein_tape(), closein_cdstream(),
|
---|
| 45 | * closeout_tape(), and closeout_cdstream().
|
---|
| 46 | */
|
---|
| 47 | FILE *g_tape_stream = NULL;
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | /**
|
---|
| 51 | * The position (in kilobytes) where we are on the tape.
|
---|
| 52 | */
|
---|
| 53 | long long g_tape_posK = 0;
|
---|
| 54 |
|
---|
| 55 | /**
|
---|
| 56 | * The current media number we're using. This value is 1-based.
|
---|
| 57 | */
|
---|
[128] | 58 | int g_current_media_number = -1;
|
---|
[1] | 59 |
|
---|
| 60 | /**
|
---|
| 61 | * The tape catalog that keeps track of files written to tape.
|
---|
| 62 | */
|
---|
| 63 | struct s_tapecatalog *g_tapecatalog;
|
---|
| 64 |
|
---|
| 65 | /* @} - end of globalGroup */
|
---|
| 66 |
|
---|
[128] | 67 | int write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo);
|
---|
[1] | 68 |
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | /**
|
---|
| 74 | * @addtogroup streamGroup
|
---|
| 75 | * @{
|
---|
| 76 | */
|
---|
| 77 | /**
|
---|
| 78 | * Close the global output file descriptor which Mondo has used to read
|
---|
| 79 | * from the CD stream.
|
---|
| 80 | * @param bkpinfo The backup information structure. Passed directly to closein_tape().
|
---|
| 81 | * @return 0 for success, nonzero for failure.
|
---|
| 82 | * @note This should be called by restore processes only.
|
---|
| 83 | */
|
---|
[128] | 84 | int closein_cdstream(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 85 | {
|
---|
[128] | 86 | return (closein_tape(bkpinfo));
|
---|
[1] | 87 | }
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | /**
|
---|
| 91 | * Close the global output file descriptor which Mondo has used to read
|
---|
| 92 | * from buffer or dd, which read from the tape.
|
---|
| 93 | * @param bkpinfo The backup information structure. Unused.
|
---|
| 94 | * @return 0 for success, nonzero for failure.
|
---|
| 95 | * @note This should be called by restore processes only.
|
---|
| 96 | * @note This function also works for cdstreams for now, but don't count on this behavior.
|
---|
| 97 | * @bug @p bkpinfo parameter is unused.
|
---|
| 98 | */
|
---|
[128] | 99 | int closein_tape(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 100 | {
|
---|
[128] | 101 | /*@ int's ******************************************************* */
|
---|
| 102 | int retval = 0;
|
---|
| 103 | int res = 0;
|
---|
| 104 | int ctrl_chr = '\0';
|
---|
[1] | 105 |
|
---|
[128] | 106 | /*@ buffers ***************************************************** */
|
---|
| 107 | char fname[MAX_STR_LEN];
|
---|
[1] | 108 |
|
---|
[128] | 109 | /*@ long long's ************************************************* */
|
---|
| 110 | long long size;
|
---|
| 111 | char *blk;
|
---|
| 112 | int i;
|
---|
[1] | 113 |
|
---|
[1080] | 114 | blk = (char *) mr_malloc(256 * 1024);
|
---|
[1] | 115 |
|
---|
[128] | 116 | log_it("closein_tape() -- entering");
|
---|
| 117 | res = read_header_block_from_stream(&size, fname, &ctrl_chr);
|
---|
| 118 | retval += res;
|
---|
| 119 | if (ctrl_chr != BLK_END_OF_BACKUP) {
|
---|
| 120 | wrong_marker(BLK_END_OF_BACKUP, ctrl_chr);
|
---|
| 121 | }
|
---|
| 122 | res = read_header_block_from_stream(&size, fname, &ctrl_chr);
|
---|
| 123 | retval += res;
|
---|
| 124 | if (ctrl_chr != BLK_END_OF_TAPE) {
|
---|
| 125 | wrong_marker(BLK_END_OF_TAPE, ctrl_chr);
|
---|
| 126 | }
|
---|
| 127 | for (i = 0; i < 8 && !feof(g_tape_stream); i++) {
|
---|
| 128 | (void) fread(blk, 1, 256 * 1024, g_tape_stream);
|
---|
| 129 | }
|
---|
| 130 | sleep(1);
|
---|
| 131 | paranoid_system("sync");
|
---|
| 132 | sleep(1);
|
---|
| 133 | paranoid_pclose(g_tape_stream);
|
---|
| 134 | log_it("closein_tape() -- leaving");
|
---|
[1] | 135 | /*
|
---|
| 136 | for(i=0; i < g_tapecatalog->entries; i++)
|
---|
| 137 | {
|
---|
| 138 | log_it("i=%d type=%s num=%d aux=%ld", i, (g_tapecatalog->el[i].type==fileset)?"fileset":"bigslice", g_tapecatalog->el[i].number, g_tapecatalog->el[i].aux);
|
---|
| 139 | }
|
---|
| 140 | */
|
---|
[128] | 141 | if (!bkpinfo->please_dont_eject) {
|
---|
| 142 | eject_device(bkpinfo->media_device);
|
---|
| 143 | }
|
---|
[1080] | 144 | mr_free(blk);
|
---|
| 145 | mr_free(g_tapecatalog);
|
---|
[128] | 146 | return (retval);
|
---|
[1] | 147 | }
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 |
|
---|
| 151 | /**
|
---|
| 152 | * Close the global output file descriptor which Mondo has been using to write
|
---|
| 153 | * to the tape device (via buffer or dd).
|
---|
| 154 | * @param bkpinfo The backup information structure. @c bkpinfo->media_size is the only field used.
|
---|
| 155 | * @return 0 for success, nonzero for failure.
|
---|
| 156 | * @note This should be called by backup processes only.
|
---|
| 157 | */
|
---|
[128] | 158 | int closeout_tape(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 159 | {
|
---|
[128] | 160 | /*@ int's ******************************************************* */
|
---|
| 161 | int retval = 0;
|
---|
[1] | 162 | // int res = 0;
|
---|
| 163 | // int ctrl_chr = '\0';
|
---|
| 164 |
|
---|
[128] | 165 | /*@ buffers ***************************************************** */
|
---|
[1] | 166 | // char fname[MAX_STR_LEN];
|
---|
| 167 |
|
---|
[128] | 168 | /*@ long long's ************************************************* */
|
---|
[1] | 169 | // long long size;
|
---|
[128] | 170 | int i;
|
---|
| 171 | char *blk;
|
---|
[1] | 172 |
|
---|
[1080] | 173 | blk = (char *) mr_malloc(256 * 1024);
|
---|
[1] | 174 |
|
---|
[128] | 175 | sleep(1);
|
---|
| 176 | paranoid_system("sync");
|
---|
| 177 | sleep(1);
|
---|
| 178 | log_it("closeout_tape() -- entering");
|
---|
| 179 | retval +=
|
---|
[684] | 180 | write_header_block_to_stream((off_t)0, "end-of-backup",
|
---|
[128] | 181 | BLK_END_OF_BACKUP);
|
---|
[684] | 182 | retval += write_header_block_to_stream((off_t)0, "end-of-tape", BLK_END_OF_TAPE); /* just in case */
|
---|
[1] | 183 | /* write 1MB of crap */
|
---|
[128] | 184 | for (i = 0; i < 256 * 1024; i++) {
|
---|
| 185 | blk[i] = (int) (random() & 0xFF);
|
---|
| 186 | }
|
---|
| 187 | for (i = 0; i < 4 * 8; i++) {
|
---|
| 188 | (void) fwrite(blk, 1, 256 * 1024, g_tape_stream);
|
---|
| 189 | if (should_we_write_to_next_tape
|
---|
[684] | 190 | (bkpinfo->media_size[g_current_media_number], (off_t)256 * 1024)) {
|
---|
[128] | 191 | start_to_write_to_next_tape(bkpinfo);
|
---|
| 192 | }
|
---|
| 193 | }
|
---|
[1] | 194 | /* write 1MB of zeroes */
|
---|
| 195 | /*
|
---|
| 196 | for (i = 0; i < 256*1024; i++)
|
---|
| 197 | {
|
---|
| 198 | blk[i] = 0;
|
---|
| 199 | }
|
---|
| 200 | for (i = 0; i < 4; i++)
|
---|
| 201 | {
|
---|
| 202 | fwrite (blk, 1, 256*1024, g_tape_stream);
|
---|
| 203 | if (should_we_write_to_next_tape (bkpinfo->media_size[g_current_media_number], 256*1024))
|
---|
| 204 | {
|
---|
| 205 | start_to_write_to_next_tape (bkpinfo);
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
| 208 | */
|
---|
[128] | 209 | sleep(2);
|
---|
| 210 | paranoid_pclose(g_tape_stream);
|
---|
| 211 | log_it("closeout_tape() -- leaving");
|
---|
| 212 | for (i = 0; i < g_tapecatalog->entries; i++) {
|
---|
| 213 | log_it("i=%d type=%s num=%d aux=%ld posK=%lld", i,
|
---|
| 214 | (g_tapecatalog->el[i].type ==
|
---|
| 215 | fileset) ? "fileset" : "bigslice",
|
---|
| 216 | g_tapecatalog->el[i].number, g_tapecatalog->el[i].aux,
|
---|
| 217 | g_tapecatalog->el[i].tape_posK);
|
---|
| 218 | }
|
---|
| 219 | // if (!bkpinfo->please_dont_eject)
|
---|
| 220 | // { eject_device(bkpinfo->media_device); }
|
---|
[1080] | 221 | mr_free(blk);
|
---|
| 222 | mr_free(g_tapecatalog);
|
---|
[128] | 223 | return (retval);
|
---|
[1] | 224 | }
|
---|
| 225 |
|
---|
| 226 |
|
---|
| 227 |
|
---|
[128] | 228 | bool mt_says_tape_exists(char *dev)
|
---|
[1] | 229 | {
|
---|
[128] | 230 | char *command;
|
---|
| 231 | int res;
|
---|
[1] | 232 |
|
---|
[128] | 233 | malloc_string(command);
|
---|
| 234 | sprintf(command, "mt -f %s status", dev);
|
---|
| 235 | res = run_program_and_log_output(command, 1);
|
---|
[1080] | 236 | mr_free(command);
|
---|
[128] | 237 | if (res) {
|
---|
| 238 | return (FALSE);
|
---|
| 239 | } else {
|
---|
| 240 | return (TRUE);
|
---|
| 241 | }
|
---|
[1] | 242 | }
|
---|
| 243 |
|
---|
| 244 |
|
---|
| 245 |
|
---|
| 246 | /**
|
---|
| 247 | * Determine the name and size of the tape device. Tries the SCSI tape for
|
---|
| 248 | * this platform, then the IDE tape, then "/dev/st0", then "/dev/osst0".
|
---|
| 249 | * @param dev Where to put the found tape device.
|
---|
| 250 | * @param siz Where to put the tape size (a string like "4GB")
|
---|
| 251 | * @return 0 if success, nonzero if failure (in which @p dev and @p siz are undefined).
|
---|
| 252 | */
|
---|
[128] | 253 | int find_tape_device_and_size(char *dev, char *siz)
|
---|
[1] | 254 | {
|
---|
[128] | 255 | char tmp[MAX_STR_LEN];
|
---|
| 256 | char command[MAX_STR_LEN * 2];
|
---|
| 257 | char cdr_exe[MAX_STR_LEN];
|
---|
[1] | 258 | // char tape_description_[MAX_STR_LEN];
|
---|
| 259 | // char tape_manufacturer_cdr[MAX_STR_LEN];
|
---|
| 260 | // FILE*fin;
|
---|
[128] | 261 | int res;
|
---|
[1] | 262 |
|
---|
[128] | 263 | log_to_screen("I am looking for your tape streamer. Please wait.");
|
---|
| 264 | dev[0] = siz[0] = '\0';
|
---|
| 265 | if (find_home_of_exe("cdrecord")) {
|
---|
| 266 | strcpy(cdr_exe, "cdrecord");
|
---|
| 267 | } else {
|
---|
| 268 | strcpy(cdr_exe, "dvdrecord");
|
---|
[1] | 269 | }
|
---|
[128] | 270 | sprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l",
|
---|
| 271 | cdr_exe);
|
---|
| 272 | strcpy(tmp, call_program_and_get_last_line_of_output(command));
|
---|
| 273 | if (atoi(tmp) != 1) {
|
---|
| 274 | log_it
|
---|
| 275 | ("Either too few or too many tape streamers for me to detect...");
|
---|
| 276 | strcpy(dev, VANILLA_SCSI_TAPE);
|
---|
| 277 | return 1;
|
---|
| 278 | }
|
---|
| 279 | sprintf(command,
|
---|
| 280 | "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1",
|
---|
| 281 | cdr_exe);
|
---|
| 282 | strcpy(tmp, call_program_and_get_last_line_of_output(command));
|
---|
| 283 | if (strlen(tmp) < 2) {
|
---|
| 284 | log_it("Could not find tape device");
|
---|
| 285 | return 1;
|
---|
| 286 | }
|
---|
| 287 | sprintf(command,
|
---|
| 288 | "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f3 | cut -d')' -f1 | head -n1",
|
---|
| 289 | cdr_exe);
|
---|
| 290 | strcpy(tmp, call_program_and_get_last_line_of_output(command));
|
---|
| 291 | strcpy(dev, VANILLA_SCSI_TAPE);
|
---|
| 292 | dev[strlen(dev) - 1] = '\0';
|
---|
| 293 | strcat(dev, tmp); // e.g. '/dev/st0' becomes '/dev/stN'
|
---|
| 294 | res = 0;
|
---|
| 295 | if (!mt_says_tape_exists(dev)) {
|
---|
| 296 | strcpy(dev, ALT_TAPE);
|
---|
| 297 | if (!mt_says_tape_exists(dev)) {
|
---|
| 298 | log_it("Cannot openin %s", dev);
|
---|
| 299 | strcpy(dev, "/dev/st0");
|
---|
| 300 | if (!mt_says_tape_exists(dev)) {
|
---|
| 301 | log_it("Cannot openin %s", dev);
|
---|
| 302 | strcpy(dev, "/dev/osst0");
|
---|
| 303 | if (!mt_says_tape_exists(dev)) {
|
---|
| 304 | res++;
|
---|
| 305 | } else {
|
---|
| 306 | res = 0;
|
---|
| 307 | }
|
---|
| 308 | }
|
---|
| 309 | }
|
---|
| 310 | }
|
---|
[1] | 311 |
|
---|
[128] | 312 | log_it("At this point, dev = %s and res = %d", dev, res);
|
---|
| 313 |
|
---|
| 314 | strcpy(tmp, call_program_and_get_last_line_of_output("\
|
---|
[1] | 315 | cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | \
|
---|
| 316 | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | \
|
---|
| 317 | awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'"));
|
---|
| 318 |
|
---|
[128] | 319 | if (mt_says_tape_exists(dev)) {
|
---|
| 320 | res = 0;
|
---|
| 321 | } else {
|
---|
| 322 | log_it("Turning %s", dev);
|
---|
| 323 | strcpy(tmp, (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev);
|
---|
| 324 | sprintf(dev, "/dev/os%s", tmp);
|
---|
| 325 | log_it("...into %s", dev);
|
---|
| 326 | if (mt_says_tape_exists(dev)) {
|
---|
| 327 | res = 0;
|
---|
| 328 | } else {
|
---|
| 329 | res++;
|
---|
| 330 | }
|
---|
| 331 | }
|
---|
[1] | 332 |
|
---|
[128] | 333 | siz[0] = '\0';
|
---|
| 334 | log_it("res=%d; dev=%s", res, dev);
|
---|
[1] | 335 |
|
---|
[128] | 336 | if (res) {
|
---|
| 337 | return (res);
|
---|
| 338 | }
|
---|
[1] | 339 |
|
---|
[128] | 340 | if (strlen(tmp) < 2) {
|
---|
| 341 | siz[0] = '\0';
|
---|
| 342 | log_it("Warning - size of tape unknown");
|
---|
| 343 | return (0);
|
---|
| 344 | } else {
|
---|
| 345 | strcpy(siz, tmp);
|
---|
| 346 | return (0);
|
---|
| 347 | }
|
---|
[1] | 348 | }
|
---|
| 349 |
|
---|
| 350 |
|
---|
| 351 |
|
---|
| 352 |
|
---|
| 353 |
|
---|
| 354 |
|
---|
[128] | 355 | int read_EXAT_files_from_tape(struct s_bkpinfo *bkpinfo,
|
---|
| 356 | long long *ptmp_size, char *tmp_fname,
|
---|
| 357 | int *pctrl_chr, char *xattr_fname,
|
---|
| 358 | char *acl_fname)
|
---|
[1] | 359 | {
|
---|
[128] | 360 | int res = 0;
|
---|
| 361 | int retval = 0;
|
---|
[955] | 362 | char *fname = (char *)&res; /* Should NOT be NULL */
|
---|
[128] | 363 |
|
---|
[1] | 364 | // xattr
|
---|
[948] | 365 | if (g_getfattr) {
|
---|
[955] | 366 | res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr);
|
---|
[948] | 367 | if (*pctrl_chr != BLK_START_EXAT_FILE) {
|
---|
| 368 | wrong_marker(BLK_START_EXAT_FILE, *pctrl_chr);
|
---|
| 369 | }
|
---|
[955] | 370 | if (!strstr(fname, "xattr")) {
|
---|
[948] | 371 | fatal_error("Wrong order, sunshine.");
|
---|
| 372 | }
|
---|
| 373 | read_file_from_stream_to_file(bkpinfo, xattr_fname, *ptmp_size);
|
---|
| 374 | res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
|
---|
| 375 | if (*pctrl_chr != BLK_STOP_EXAT_FILE) {
|
---|
| 376 | wrong_marker(BLK_STOP_EXAT_FILE, *pctrl_chr);
|
---|
| 377 | }
|
---|
[1107] | 378 | mr_msg(1, "Got xattr");
|
---|
[128] | 379 | }
|
---|
[1] | 380 | // acl
|
---|
[948] | 381 | if (g_getfacl) {
|
---|
[955] | 382 | res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr);
|
---|
| 383 | if (!strstr(fname, "acl")) {
|
---|
[948] | 384 | fatal_error("Wrong order, sunshine.");
|
---|
| 385 | }
|
---|
| 386 | if (*pctrl_chr != BLK_START_EXAT_FILE) {
|
---|
| 387 | wrong_marker(BLK_START_EXAT_FILE, *pctrl_chr);
|
---|
| 388 | }
|
---|
| 389 | read_file_from_stream_to_file(bkpinfo, acl_fname, *ptmp_size);
|
---|
| 390 | res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
|
---|
| 391 | if (*pctrl_chr != BLK_STOP_EXAT_FILE) {
|
---|
| 392 | wrong_marker(BLK_STOP_EXAT_FILE, *pctrl_chr);
|
---|
| 393 | }
|
---|
| 394 | res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
|
---|
| 395 | if (*pctrl_chr != BLK_STOP_EXTENDED_ATTRIBUTES) {
|
---|
| 396 | wrong_marker(BLK_STOP_EXTENDED_ATTRIBUTES, *pctrl_chr);
|
---|
| 397 | }
|
---|
[1107] | 398 | mr_msg(1, "Got acl");
|
---|
[128] | 399 | }
|
---|
[1] | 400 | // tarball itself
|
---|
[128] | 401 | res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
|
---|
[1107] | 402 | mr_msg(1, "now looking for afioball");
|
---|
[128] | 403 | return (retval);
|
---|
[1] | 404 | }
|
---|
| 405 |
|
---|
| 406 |
|
---|
[128] | 407 | int write_EXAT_files_to_tape(struct s_bkpinfo *bkpinfo, char *xattr_fname,
|
---|
| 408 | char *acl_fname)
|
---|
[1] | 409 | {
|
---|
[128] | 410 | int res = 0;
|
---|
[948] | 411 | if (g_getfattr) {
|
---|
[955] | 412 | // xattr
|
---|
[948] | 413 | write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname,
|
---|
| 414 | BLK_START_EXTENDED_ATTRIBUTES);
|
---|
| 415 | write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname,
|
---|
| 416 | BLK_START_EXAT_FILE);
|
---|
| 417 | write_file_to_stream_from_file(bkpinfo, xattr_fname);
|
---|
| 418 | write_header_block_to_stream((off_t)-1, xattr_fname, BLK_STOP_EXAT_FILE);
|
---|
| 419 | }
|
---|
| 420 | if (g_getfacl) {
|
---|
[955] | 421 | // acl
|
---|
[948] | 422 | write_header_block_to_stream(length_of_file(acl_fname), acl_fname,
|
---|
| 423 | BLK_START_EXAT_FILE);
|
---|
| 424 | write_file_to_stream_from_file(bkpinfo, acl_fname);
|
---|
| 425 | write_header_block_to_stream((off_t)-1, acl_fname, BLK_STOP_EXAT_FILE);
|
---|
| 426 | write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname,
|
---|
| 427 | BLK_STOP_EXTENDED_ATTRIBUTES);
|
---|
| 428 | }
|
---|
[128] | 429 | return (res);
|
---|
[1] | 430 | }
|
---|
| 431 |
|
---|
| 432 |
|
---|
| 433 |
|
---|
| 434 |
|
---|
| 435 | /**
|
---|
| 436 | * Tell the user to insert tape @p tapeno and wait for it to settle (5 seconds).
|
---|
| 437 | * @param tapeno The tape number to insist on.
|
---|
| 438 | * @bug There is currently no way to actually verify that the user has actually
|
---|
| 439 | * inserted the right tape.
|
---|
| 440 | */
|
---|
| 441 | void insist_on_this_tape_number(int tapeno)
|
---|
| 442 | {
|
---|
[128] | 443 | int i;
|
---|
| 444 | char tmp[MAX_STR_LEN];
|
---|
[1] | 445 |
|
---|
[128] | 446 | log_it("Insisting on tape #%d", tapeno);
|
---|
| 447 | if (g_current_media_number != tapeno) {
|
---|
| 448 | // log_it("g_current_media_number = %d", g_current_media_number);
|
---|
| 449 | sprintf(tmp,
|
---|
[541] | 450 | "When the tape drive goes quiet, please insert volume %d in this series.",
|
---|
[128] | 451 | tapeno);
|
---|
| 452 | popup_and_OK(tmp);
|
---|
[541] | 453 | open_evalcall_form("Waiting while the tape drive settles");
|
---|
[128] | 454 | } else {
|
---|
[541] | 455 | open_evalcall_form("Waiting while the tape drive rewinds");
|
---|
[128] | 456 | }
|
---|
[1] | 457 |
|
---|
[128] | 458 | for (i = 0; i <= 100; i += 2) {
|
---|
| 459 | usleep(100000);
|
---|
| 460 | update_evalcall_form(i);
|
---|
| 461 | }
|
---|
| 462 | close_evalcall_form();
|
---|
| 463 | log_it("I assume user has inserted it. They _say_ they have...");
|
---|
| 464 | g_current_media_number = tapeno;
|
---|
[1] | 465 |
|
---|
[128] | 466 | // log_it("g_current_media_number = %d", g_current_media_number);
|
---|
| 467 | log_it("OK, I've finished insisting. On with the revelry.");
|
---|
[1] | 468 | }
|
---|
| 469 |
|
---|
| 470 |
|
---|
| 471 |
|
---|
| 472 |
|
---|
| 473 | /**
|
---|
| 474 | * Debugging aid - log the offset we're at on the tape (reading or writing).
|
---|
| 475 | */
|
---|
[128] | 476 | void log_tape_pos(void)
|
---|
[1] | 477 | {
|
---|
[128] | 478 | /*@ buffers ***************************************************** */
|
---|
[1] | 479 |
|
---|
| 480 |
|
---|
[128] | 481 | /*@ end vars *************************************************** */
|
---|
[1] | 482 |
|
---|
[128] | 483 | log_it("Tape position -- %ld KB (%ld MB)", (long) g_tape_posK,
|
---|
| 484 | (long) g_tape_posK >> 10);
|
---|
[1] | 485 | }
|
---|
| 486 |
|
---|
| 487 |
|
---|
| 488 |
|
---|
| 489 |
|
---|
| 490 | /**
|
---|
| 491 | * Add a file to a collection of recently archived filesets/slices.
|
---|
| 492 | * The type is determined by the filename: if it contains ".afio." it is
|
---|
| 493 | * assumed to be a fileset, otherwise if it contains "slice" it's a slice,
|
---|
| 494 | * otherwise we generate a fatal_error().
|
---|
| 495 | * @param td The current @c bkpinfo->tempdir (file will be placed in <tt>td</tt>/tmpfs/backcatalog/).
|
---|
| 496 | * @param latest_fname The file to place in the collection.
|
---|
| 497 | * @return 0, always.
|
---|
| 498 | * @bug Return value is redundant.
|
---|
| 499 | * @bug The detection won't work for uncompressed afioballs (they end in ".afio", no dot afterwards). // Not true. They end in '.' -Hugo
|
---|
| 500 | */
|
---|
| 501 | int maintain_collection_of_recent_archives(char *td, char *latest_fname)
|
---|
| 502 | {
|
---|
[128] | 503 | long long final_alleged_writeK, final_projected_certain_writeK,
|
---|
| 504 | final_actually_certain_writeK = 0, cposK, bufsize_K;
|
---|
| 505 | int last, curr, i;
|
---|
| 506 | t_archtype type = other;
|
---|
| 507 | char command[MAX_STR_LEN];
|
---|
| 508 | char tmpdir[MAX_STR_LEN];
|
---|
| 509 | char old_fname[MAX_STR_LEN];
|
---|
| 510 | char *p;
|
---|
| 511 | char suffix[16];
|
---|
[1] | 512 |
|
---|
[128] | 513 | bufsize_K = (long long) (1024LL * (1 + g_tape_buffer_size_MB));
|
---|
| 514 | sprintf(tmpdir, "%s/tmpfs/backcatalog", td);
|
---|
| 515 | if ((p = strrchr(latest_fname, '.'))) {
|
---|
| 516 | strcpy(suffix, ++p);
|
---|
| 517 | } else {
|
---|
| 518 | suffix[0] = '\0';
|
---|
[1] | 519 | }
|
---|
[128] | 520 | if (strstr(latest_fname, ".afio.") || strstr(latest_fname, ".star.")) {
|
---|
| 521 | type = fileset;
|
---|
| 522 | } else if (strstr(latest_fname, "slice")) {
|
---|
| 523 | type = biggieslice;
|
---|
| 524 | } else {
|
---|
| 525 | log_it("fname = %s", latest_fname);
|
---|
| 526 | fatal_error
|
---|
| 527 | ("Unknown type. Internal error in maintain_collection_of_recent_archives()");
|
---|
| 528 | }
|
---|
| 529 | mkdir(tmpdir, 0x700);
|
---|
| 530 | sprintf(command, "cp -f %s %s", latest_fname, tmpdir);
|
---|
| 531 | if (run_program_and_log_output(command, 6)) {
|
---|
| 532 | log_it("Warning - failed to copy %s to backcatalog at %s",
|
---|
| 533 | latest_fname, tmpdir);
|
---|
| 534 | }
|
---|
| 535 | last = g_tapecatalog->entries - 1;
|
---|
| 536 | if (last <= 0) {
|
---|
| 537 | iamhere("Too early to start deleting from collection.");
|
---|
| 538 | return (0);
|
---|
| 539 | }
|
---|
| 540 | final_alleged_writeK = g_tapecatalog->el[last].tape_posK;
|
---|
| 541 | final_projected_certain_writeK = final_alleged_writeK - bufsize_K;
|
---|
| 542 | for (curr = last; curr >= 0; curr--) {
|
---|
| 543 | cposK = g_tapecatalog->el[curr].tape_posK;
|
---|
| 544 | if (cposK < final_projected_certain_writeK) {
|
---|
| 545 | final_actually_certain_writeK = cposK;
|
---|
| 546 | break;
|
---|
| 547 | }
|
---|
| 548 | }
|
---|
| 549 | if (curr < 0) {
|
---|
| 550 | iamhere
|
---|
| 551 | ("Not far enough into tape to start deleting old archives from collection.");
|
---|
| 552 | return (0);
|
---|
| 553 | }
|
---|
[1] | 554 | // log_it( "There are %lld KB (more than %d KB) in my backcatalog", final_alleged_writeK - final_actually_certain_writeK, bufsize_K);
|
---|
| 555 |
|
---|
[128] | 556 | for (i = curr - 1; i >= 0 && curr - i < 10; i--) {
|
---|
| 557 | sprintf(old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname);
|
---|
| 558 | unlink(old_fname);
|
---|
| 559 | }
|
---|
| 560 | return (0);
|
---|
[1] | 561 | }
|
---|
| 562 |
|
---|
| 563 |
|
---|
| 564 |
|
---|
| 565 |
|
---|
| 566 | /**
|
---|
| 567 | * Open the CD stream for input.
|
---|
| 568 | * @param bkpinfo The backup information structure. Passed to openin_tape().
|
---|
| 569 | * @return 0 for success, nonzero for failure.
|
---|
| 570 | * @note Equivalent to openin_tape() for now, but don't count on this behavior.
|
---|
| 571 | */
|
---|
[128] | 572 | int openin_cdstream(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 573 | {
|
---|
[128] | 574 | return (openin_tape(bkpinfo));
|
---|
[1] | 575 | }
|
---|
| 576 |
|
---|
| 577 | /**
|
---|
| 578 | * FIFO used to read/write to the tape device.
|
---|
| 579 | * @bug This seems obsolete now that we call an external @c buffer program. Please look onto this.
|
---|
| 580 | */
|
---|
| 581 | char g_tape_fifo[MAX_STR_LEN];
|
---|
| 582 |
|
---|
| 583 |
|
---|
| 584 |
|
---|
[128] | 585 | int set_tape_block_size_with_mt(char *tapedev,
|
---|
| 586 | long internal_tape_block_size)
|
---|
[1] | 587 | {
|
---|
[128] | 588 | char *tmp;
|
---|
| 589 | int res;
|
---|
[1] | 590 |
|
---|
[128] | 591 | if (strncmp(tapedev, "/dev/", 5)) {
|
---|
[1107] | 592 | mr_msg(1,
|
---|
[128] | 593 | "Not using 'mt setblk'. This isn't an actual /dev entry.");
|
---|
| 594 | return (0);
|
---|
| 595 | }
|
---|
| 596 | malloc_string(tmp);
|
---|
| 597 | sprintf(tmp, "mt -f %s setblk %ld", tapedev, internal_tape_block_size);
|
---|
| 598 | res = run_program_and_log_output(tmp, 3);
|
---|
[1080] | 599 | mr_free(tmp);
|
---|
[128] | 600 | return (res);
|
---|
[1] | 601 | }
|
---|
| 602 |
|
---|
| 603 |
|
---|
| 604 |
|
---|
| 605 | /**
|
---|
| 606 | * Open the tape device for input.
|
---|
| 607 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 608 | * - @c bkpinfo->media_device
|
---|
| 609 | * - @c bkpinfo->tmpdir
|
---|
| 610 | * @return 0 for success, nonzero for failure.
|
---|
| 611 | * @note This will also work with a cdstream for now, but don't count on this behavior.
|
---|
| 612 | */
|
---|
[128] | 613 | int openin_tape(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 614 | {
|
---|
[128] | 615 | /*@ buffer ***************************************************** */
|
---|
| 616 | char fname[MAX_STR_LEN];
|
---|
| 617 | char *datablock;
|
---|
| 618 | char tmp[MAX_STR_LEN];
|
---|
| 619 | char old_cwd[MAX_STR_LEN];
|
---|
| 620 | char outfname[MAX_STR_LEN];
|
---|
| 621 | /*@ int ******************************************************* */
|
---|
| 622 | int i;
|
---|
| 623 | int j;
|
---|
| 624 | int res;
|
---|
| 625 | long length, templong;
|
---|
| 626 | size_t k;
|
---|
| 627 | int retval = 0;
|
---|
| 628 | int ctrl_chr;
|
---|
[1] | 629 |
|
---|
[128] | 630 | /*@ long long ************************************************* */
|
---|
| 631 | long long size;
|
---|
[1] | 632 |
|
---|
[128] | 633 | /*@ pointers ************************************************** */
|
---|
| 634 | FILE *fout;
|
---|
[1] | 635 |
|
---|
[128] | 636 | /*@ end vars *************************************************** */
|
---|
[1] | 637 |
|
---|
[128] | 638 | assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device);
|
---|
[1080] | 639 | g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog));
|
---|
[128] | 640 | g_tapecatalog->entries = 0;
|
---|
| 641 | g_tape_posK = 0;
|
---|
| 642 | if (g_tape_stream) {
|
---|
| 643 | log_it("FYI - I won't 'openin' the tape. It's already open.");
|
---|
| 644 | return (0);
|
---|
| 645 | }
|
---|
| 646 | insist_on_this_tape_number(1);
|
---|
| 647 | sprintf(outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir);
|
---|
| 648 | make_hole_for_file(outfname);
|
---|
[1] | 649 |
|
---|
[128] | 650 | set_tape_block_size_with_mt(bkpinfo->media_device,
|
---|
| 651 | bkpinfo->internal_tape_block_size);
|
---|
[1] | 652 |
|
---|
| 653 | // start_buffer_process( bkpinfo->media_device, g_tape_fifo, FALSE);
|
---|
[128] | 654 | log_it("Opening IN tape");
|
---|
| 655 | if (!
|
---|
| 656 | (g_tape_stream =
|
---|
| 657 | open_device_via_buffer(bkpinfo->media_device, 'r',
|
---|
| 658 | bkpinfo->internal_tape_block_size))) {
|
---|
| 659 | log_OS_error(g_tape_fifo);
|
---|
[541] | 660 | log_to_screen("Cannot openin stream device");
|
---|
[128] | 661 | return (1);
|
---|
| 662 | }
|
---|
[541] | 663 | log_to_screen("Reading stream");
|
---|
[128] | 664 | log_it("stream device = '%s'", bkpinfo->media_device);
|
---|
[1] | 665 | /* skip data disks */
|
---|
[128] | 666 | open_evalcall_form("Skipping data disks on stream");
|
---|
[541] | 667 | log_to_screen("Skipping data disks on stream");
|
---|
[128] | 668 | if (!(fout = fopen(outfname, "w"))) {
|
---|
| 669 | log_OS_error(outfname);
|
---|
[541] | 670 | log_to_screen("Cannot openout datadisk all.tar.gz file");
|
---|
[128] | 671 | return (-1);
|
---|
[1] | 672 | }
|
---|
[1080] | 673 | datablock = (char *) mr_malloc(256 * 1024);
|
---|
[128] | 674 | for (i = 0; i < 32; i++) {
|
---|
| 675 | for (j = 0; j < 4; j++) {
|
---|
| 676 | for (length = 0, k = 0; length < 256 * 1024; length += k) {
|
---|
| 677 | k = fread(datablock + length, 1, 256 * 1024 - length,
|
---|
| 678 | g_tape_stream);
|
---|
| 679 | }
|
---|
| 680 | (void) fwrite(datablock, 1, (size_t) length, fout);
|
---|
| 681 | g_tape_posK += length / 1024;
|
---|
| 682 | }
|
---|
| 683 | if (i > 8) // otherwise, 'buffer' distorts calculations
|
---|
| 684 | {
|
---|
| 685 | templong = ((i - 8) * 4 + j) * 100 / (128 - 8 * 4);
|
---|
| 686 | update_evalcall_form((int) (templong));
|
---|
| 687 | }
|
---|
| 688 | }
|
---|
| 689 | paranoid_fclose(fout);
|
---|
[1080] | 690 | mr_free(datablock);
|
---|
[1] | 691 | /* find initial blocks */
|
---|
[128] | 692 | res = read_header_block_from_stream(&size, fname, &ctrl_chr);
|
---|
| 693 | retval += res;
|
---|
| 694 | if (ctrl_chr != BLK_START_OF_TAPE) {
|
---|
| 695 | wrong_marker(BLK_START_OF_TAPE, ctrl_chr);
|
---|
| 696 | }
|
---|
| 697 | res = read_header_block_from_stream(&size, fname, &ctrl_chr);
|
---|
| 698 | retval += res;
|
---|
| 699 | if (ctrl_chr != BLK_START_OF_BACKUP) {
|
---|
| 700 | wrong_marker(BLK_START_OF_BACKUP, ctrl_chr);
|
---|
| 701 | }
|
---|
| 702 | close_evalcall_form();
|
---|
| 703 | log_it("Saved all.tar.gz to '%s'", outfname);
|
---|
| 704 | (void) getcwd(old_cwd, MAX_STR_LEN);
|
---|
| 705 | chdir(bkpinfo->tmpdir);
|
---|
| 706 | sprintf(tmp, "tar -zxf %s tmp/mondo-restore.cfg 2> /dev/null",
|
---|
| 707 | outfname);
|
---|
| 708 | paranoid_system(tmp);
|
---|
| 709 | paranoid_system("cp -f tmp/mondo-restore.cfg . 2> /dev/null");
|
---|
| 710 | chdir(old_cwd);
|
---|
| 711 | unlink(outfname);
|
---|
| 712 | return (retval);
|
---|
[1] | 713 | }
|
---|
| 714 |
|
---|
| 715 |
|
---|
| 716 | /**
|
---|
| 717 | * Start writing to a CD stream.
|
---|
| 718 | * @param cddev The CD device to openout via cdrecord.
|
---|
| 719 | * @param speed The speed to write at.
|
---|
| 720 | * @return 0 for success, nonzero for failure.
|
---|
| 721 | * @note This should be called only from backup processes.
|
---|
| 722 | */
|
---|
[128] | 723 | int openout_cdstream(char *cddev, int speed)
|
---|
[1] | 724 | {
|
---|
[128] | 725 | /*@ buffers ***************************************************** */
|
---|
| 726 | char command[MAX_STR_LEN * 2];
|
---|
[1] | 727 |
|
---|
[128] | 728 | /*@ end vars *************************************************** */
|
---|
[1] | 729 |
|
---|
| 730 | /* add 'dummy' if testing */
|
---|
[128] | 731 | sprintf(command,
|
---|
| 732 | "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s",
|
---|
| 733 | cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE);
|
---|
[1] | 734 | /* initialise the catalog */
|
---|
[128] | 735 | g_current_media_number = 1;
|
---|
[1080] | 736 | g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog));
|
---|
[128] | 737 | g_tapecatalog->entries = 0;
|
---|
[1] | 738 | /* log stuff */
|
---|
[128] | 739 | log_it("Opening OUT cdstream with the command");
|
---|
| 740 | log_it(command);
|
---|
[1] | 741 | /* log_it("Let's see what happens, shall we?"); */
|
---|
[128] | 742 | g_tape_stream = popen(command, "w");
|
---|
| 743 | if (g_tape_stream) {
|
---|
| 744 | return (0);
|
---|
| 745 | } else {
|
---|
[541] | 746 | log_to_screen("Failed to openout to cdstream (fifo)");
|
---|
[128] | 747 | return (1);
|
---|
| 748 | }
|
---|
[1] | 749 | }
|
---|
| 750 |
|
---|
| 751 | /**
|
---|
| 752 | * Start writing to a tape device for the backup.
|
---|
| 753 | * @param tapedev The tape device to open for writing.
|
---|
| 754 | * @return 0 for success, nonzero for failure.
|
---|
| 755 | * @note This should be called ONLY from backup processes. It will OVERWRITE ANY
|
---|
| 756 | * EXISTING DATA on the tape!
|
---|
| 757 | */
|
---|
[128] | 758 | int openout_tape(char *tapedev, long internal_tape_block_size)
|
---|
[1] | 759 | {
|
---|
| 760 | // char sz_call_to_buffer[MAX_STR_LEN];
|
---|
| 761 |
|
---|
[128] | 762 | g_current_media_number = 1;
|
---|
| 763 | if (g_tape_stream) {
|
---|
| 764 | log_it("FYI - I won't 'openout' the tape. It's already open.");
|
---|
| 765 | return (0);
|
---|
| 766 | }
|
---|
[1080] | 767 | g_tapecatalog = mr_malloc(sizeof(struct s_tapecatalog));
|
---|
[128] | 768 | g_tapecatalog->entries = 0;
|
---|
| 769 | g_tape_posK = 0;
|
---|
| 770 |
|
---|
| 771 | set_tape_block_size_with_mt(tapedev, internal_tape_block_size);
|
---|
| 772 | log_it("Opening OUT tape");
|
---|
| 773 | if (!
|
---|
| 774 | (g_tape_stream =
|
---|
| 775 | open_device_via_buffer(tapedev, 'w', internal_tape_block_size))) {
|
---|
| 776 | log_OS_error(g_tape_fifo);
|
---|
[541] | 777 | log_to_screen("Cannot openin stream device");
|
---|
[128] | 778 | return (1);
|
---|
| 779 | }
|
---|
| 780 | return (0);
|
---|
[1] | 781 | }
|
---|
| 782 |
|
---|
| 783 |
|
---|
| 784 |
|
---|
| 785 |
|
---|
| 786 | /**
|
---|
| 787 | * Copy a file from the opened stream (CD or tape) to @p outfile.
|
---|
| 788 | * @param bkpinfo The backup information structure. @c bkpinfo->media_device is the only field used.
|
---|
| 789 | * @param outfile The file to write to.
|
---|
| 790 | * @param size The size of the file in the input stream.
|
---|
| 791 | * @return 0 for success, nonzero for failure.
|
---|
| 792 | */
|
---|
| 793 | int
|
---|
[128] | 794 | read_file_from_stream_to_file(struct s_bkpinfo *bkpinfo, char *outfile,
|
---|
| 795 | long long size)
|
---|
[1] | 796 | {
|
---|
| 797 |
|
---|
[128] | 798 | /*@ int ******************************************************** */
|
---|
| 799 | int res;
|
---|
[1] | 800 |
|
---|
[128] | 801 | /*@ end vars *************************************************** */
|
---|
[1] | 802 |
|
---|
[128] | 803 | res = read_file_from_stream_FULL(bkpinfo, outfile, NULL, size);
|
---|
[1] | 804 |
|
---|
[128] | 805 | return (res);
|
---|
[1] | 806 | }
|
---|
| 807 |
|
---|
| 808 |
|
---|
| 809 |
|
---|
| 810 | /**
|
---|
| 811 | * Copy a file from the currently opened stream (CD or tape) to the stream indicated
|
---|
| 812 | * by @p fout.
|
---|
| 813 | * @param bkpinfo The backup information structure. @c bkpinfo->media_size is the only field used.
|
---|
| 814 | * @param fout The stream to write the file to.
|
---|
| 815 | * @param size The size of the file in bytes.
|
---|
| 816 | * @return 0 for success, nonzero for failure.
|
---|
| 817 | */
|
---|
| 818 | int
|
---|
[128] | 819 | read_file_from_stream_to_stream(struct s_bkpinfo *bkpinfo, FILE * fout,
|
---|
| 820 | long long size)
|
---|
[1] | 821 | {
|
---|
| 822 |
|
---|
[128] | 823 | /*@ int ******************************************************** */
|
---|
| 824 | int res;
|
---|
[1] | 825 |
|
---|
[128] | 826 | /*@ end vars *************************************************** */
|
---|
[1] | 827 |
|
---|
[128] | 828 | res = read_file_from_stream_FULL(bkpinfo, NULL, fout, size);
|
---|
[1] | 829 | /* fflush(g_tape_stream);
|
---|
| 830 | fflush(fout);*/
|
---|
[128] | 831 | return (res);
|
---|
[1] | 832 | }
|
---|
| 833 |
|
---|
| 834 |
|
---|
| 835 |
|
---|
| 836 | /**
|
---|
| 837 | * Copy a file from the currently opened stream (CD or tape) to either a
|
---|
| 838 | * @c FILE pointer indicating a currently-opened file, or a filename indicating
|
---|
| 839 | * a new file to create. This is the backbone function that read_file_from_stream_to_file()
|
---|
| 840 | * and read_file_from_stream_to_stream() are wrappers for.
|
---|
| 841 | * @param bkpinfo The backup information structure. @c bkpinfo->media_size is the only field used.
|
---|
| 842 | * @param outfname If non-NULL, write to this file.
|
---|
| 843 | * @param foutstream If non-NULL, write to this stream.
|
---|
| 844 | * @param orig_size The original length of the file in bytes.
|
---|
| 845 | * @return 0 for success, nonzero for failure.
|
---|
| 846 | * @note Only @b one of @p outfname or @p foutstream may be non-NULL.
|
---|
| 847 | */
|
---|
| 848 | int
|
---|
[128] | 849 | read_file_from_stream_FULL(struct s_bkpinfo *bkpinfo, char *outfname,
|
---|
| 850 | FILE * foutstream, long long orig_size)
|
---|
[1] | 851 | {
|
---|
[128] | 852 | /*@ buffers ***************************************************** */
|
---|
| 853 | char *tmp;
|
---|
| 854 | char *datablock;
|
---|
| 855 | char *temp_fname;
|
---|
| 856 | char *temp_cksum;
|
---|
| 857 | char *actual_cksum;
|
---|
[1] | 858 | // char *pA, *pB;
|
---|
| 859 |
|
---|
[128] | 860 | /*@ int ********************************************************* */
|
---|
| 861 | int retval = 0;
|
---|
[1] | 862 | #ifdef EXTRA_TAPE_CHECKSUMS
|
---|
[128] | 863 | int i, ch;
|
---|
[1] | 864 | #endif
|
---|
[128] | 865 | int noof_blocks;
|
---|
| 866 | int ctrl_chr;
|
---|
| 867 | int res;
|
---|
| 868 | /*@ pointers **************************************************** */
|
---|
| 869 | FILE *fout;
|
---|
[1] | 870 |
|
---|
[128] | 871 | /*@ long ***************************************************** */
|
---|
| 872 | long bytes_to_write = 0 /*,i */ ;
|
---|
[1] | 873 | // long bytes_successfully_read_in_this_time = 0;
|
---|
| 874 |
|
---|
[128] | 875 | /*@ long long *************************************************** */
|
---|
| 876 | long long temp_size, size;
|
---|
| 877 | long bytes_read, bytes_to_read;
|
---|
| 878 | long long total_read_from_tape_for_this_file = 0;
|
---|
| 879 | long long where_I_was_before_tape_change = 0;
|
---|
| 880 | /*@ unsigned int ************************************************ */
|
---|
| 881 | /* unsigned int ch; */
|
---|
| 882 | unsigned int crc16;
|
---|
| 883 | unsigned int crctt;
|
---|
[1] | 884 |
|
---|
[128] | 885 | bool had_to_resync = FALSE;
|
---|
[1] | 886 |
|
---|
[128] | 887 | /*@ init ******************************************************* */
|
---|
| 888 | malloc_string(tmp);
|
---|
| 889 | malloc_string(temp_fname);
|
---|
| 890 | malloc_string(temp_cksum);
|
---|
| 891 | malloc_string(actual_cksum);
|
---|
[1080] | 892 | datablock = mr_malloc(TAPE_BLOCK_SIZE);
|
---|
[128] | 893 | crc16 = 0;
|
---|
| 894 | crctt = 0;
|
---|
| 895 | size = orig_size;
|
---|
[1] | 896 |
|
---|
[128] | 897 | /*@ end vars *************************************************** */
|
---|
[1] | 898 |
|
---|
[128] | 899 | res = read_header_block_from_stream(&temp_size, temp_fname, &ctrl_chr);
|
---|
| 900 | if (orig_size != temp_size && orig_size != -1) {
|
---|
| 901 | sprintf(tmp,
|
---|
| 902 | "output file's size should be %ld K but is apparently %ld K",
|
---|
| 903 | (long) size >> 10, (long) temp_size >> 10);
|
---|
| 904 | log_to_screen(tmp);
|
---|
| 905 | }
|
---|
| 906 | if (ctrl_chr != BLK_START_FILE) {
|
---|
| 907 | wrong_marker(BLK_START_FILE, ctrl_chr);
|
---|
| 908 | return (1);
|
---|
| 909 | }
|
---|
| 910 | sprintf(tmp, "Reading file from tape; writing to '%s'; %ld KB",
|
---|
| 911 | outfname, (long) size >> 10);
|
---|
[1] | 912 |
|
---|
[128] | 913 | if (foutstream) {
|
---|
| 914 | fout = foutstream;
|
---|
| 915 | } else {
|
---|
| 916 | fout = fopen(outfname, "w");
|
---|
[1] | 917 | }
|
---|
[128] | 918 | if (!fout) {
|
---|
| 919 | log_OS_error(outfname);
|
---|
[541] | 920 | log_to_screen("Cannot openout file");
|
---|
[128] | 921 | return (1);
|
---|
| 922 | }
|
---|
| 923 | total_read_from_tape_for_this_file = 0;
|
---|
| 924 | for (noof_blocks = 0; size > 0;
|
---|
| 925 | noof_blocks++, size -=
|
---|
| 926 | bytes_to_write, total_read_from_tape_for_this_file +=
|
---|
| 927 | bytes_read) {
|
---|
| 928 | bytes_to_write =
|
---|
| 929 | (size < TAPE_BLOCK_SIZE) ? (long) size : TAPE_BLOCK_SIZE;
|
---|
| 930 | bytes_to_read = TAPE_BLOCK_SIZE;
|
---|
| 931 | bytes_read = fread(datablock, 1, bytes_to_read, g_tape_stream);
|
---|
| 932 | while (bytes_read < bytes_to_read) { // next tape!
|
---|
| 933 | // crctt=crc16=0;
|
---|
| 934 | where_I_was_before_tape_change = size;
|
---|
[1107] | 935 | mr_msg(4, "where_I_was_... = %lld",
|
---|
[128] | 936 | where_I_was_before_tape_change);
|
---|
| 937 | start_to_read_from_next_tape(bkpinfo);
|
---|
[1107] | 938 | mr_msg(4, "Started reading from next tape.");
|
---|
[128] | 939 | skip_incoming_files_until_we_find_this_one(temp_fname);
|
---|
[1107] | 940 | mr_msg(4, "Skipped irrelevant files OK.");
|
---|
[128] | 941 | for (size = orig_size; size > where_I_was_before_tape_change;
|
---|
| 942 | size -= bytes_to_write) {
|
---|
| 943 | bytes_read =
|
---|
| 944 | fread(datablock, 1, bytes_to_read, g_tape_stream);
|
---|
| 945 | }
|
---|
[1107] | 946 | mr_msg(4, "'size' is now %lld (should be %lld)", size,
|
---|
[128] | 947 | where_I_was_before_tape_change);
|
---|
| 948 | log_to_screen("Successfully re-sync'd tape");
|
---|
| 949 | had_to_resync = TRUE;
|
---|
| 950 | bytes_read = fread(datablock, 1, bytes_to_read, g_tape_stream);
|
---|
| 951 | }
|
---|
[1] | 952 |
|
---|
[128] | 953 | (void) fwrite(datablock, 1, (size_t) bytes_to_write, fout); // for blocking reasons, bytes_successfully_read_in isn't necessarily the same as bytes_to_write
|
---|
[1] | 954 |
|
---|
| 955 | #ifdef EXTRA_TAPE_CHECKSUMS
|
---|
[128] | 956 | for (i = 0; i < (int) bytes_to_write; i++) {
|
---|
| 957 | ch = datablock[i];
|
---|
| 958 | crc16 = updcrcr(crc16, (unsigned) ch);
|
---|
| 959 | crctt = updcrc(crctt, (unsigned) ch);
|
---|
| 960 | }
|
---|
[1] | 961 | #endif
|
---|
[128] | 962 | }
|
---|
[1107] | 963 | mr_msg(6, "Total read from tape for this file = %lld",
|
---|
[128] | 964 | total_read_from_tape_for_this_file);
|
---|
[1107] | 965 | mr_msg(6, ".......................... Should be %lld", orig_size);
|
---|
[128] | 966 | g_tape_posK += total_read_from_tape_for_this_file / 1024;
|
---|
| 967 | sprintf(actual_cksum, "%04x%04x", crc16, crctt);
|
---|
| 968 | if (foutstream) { /*log_it("Finished writing to foutstream"); */
|
---|
| 969 | } else {
|
---|
| 970 | paranoid_fclose(fout);
|
---|
| 971 | }
|
---|
| 972 | res = read_header_block_from_stream(&temp_size, temp_cksum, &ctrl_chr);
|
---|
| 973 | if (ctrl_chr != BLK_STOP_FILE) {
|
---|
| 974 | wrong_marker(BLK_STOP_FILE, ctrl_chr);
|
---|
[1] | 975 | // fatal_error("Bad marker"); // return(1);
|
---|
[128] | 976 | }
|
---|
| 977 | if (strcmp(temp_cksum, actual_cksum)) {
|
---|
[541] | 978 | sprintf(tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum,
|
---|
[128] | 979 | temp_cksum);
|
---|
| 980 | log_to_screen(tmp);
|
---|
[541] | 981 | sprintf(tmp, "%s (%ld K) is corrupt on tape", temp_fname,
|
---|
[128] | 982 | (long) orig_size >> 10);
|
---|
| 983 | log_to_screen(tmp);
|
---|
| 984 | retval++;
|
---|
| 985 | } else {
|
---|
| 986 | sprintf(tmp, "%s is GOOD on tape", temp_fname);
|
---|
| 987 | /* log_it(tmp); */
|
---|
| 988 | }
|
---|
[1080] | 989 | mr_free(datablock);
|
---|
| 990 | mr_free(tmp);
|
---|
| 991 | mr_free(temp_fname);
|
---|
| 992 | mr_free(temp_cksum);
|
---|
| 993 | mr_free(actual_cksum);
|
---|
[128] | 994 | return (retval);
|
---|
[1] | 995 | }
|
---|
| 996 |
|
---|
| 997 |
|
---|
| 998 |
|
---|
| 999 | /**
|
---|
| 1000 | * Read a header block from the currently opened stream (CD or tape).
|
---|
| 1001 | * This block indicates the length of the following file (if it's file-related)
|
---|
| 1002 | * the filename (if it's file-related), and the block type.
|
---|
| 1003 | * @param plen Where to put the length of the file. Valid only for file-related header blocks.
|
---|
| 1004 | * @param filename Where to put the name of the file. Valid only for file-related header blocks.
|
---|
| 1005 | * @param pcontrol_char Where to put the type of block (e.g. start-file, end-file, start-tape, ...)
|
---|
| 1006 | * @return 0 for success, nonzero for failure.
|
---|
| 1007 | * @note If you read a marker (@p pcontrol_char) you're not expecting, you can call wrong_marker().
|
---|
| 1008 | */
|
---|
| 1009 | int
|
---|
[128] | 1010 | read_header_block_from_stream(long long *plen, char *filename,
|
---|
| 1011 | int *pcontrol_char)
|
---|
[1] | 1012 | {
|
---|
| 1013 |
|
---|
[128] | 1014 | /*@ buffers ***************************************************** */
|
---|
| 1015 | char *tempblock;
|
---|
[1] | 1016 |
|
---|
[128] | 1017 | /*@ int ********************************************************* */
|
---|
| 1018 | int i, retval;
|
---|
[1] | 1019 |
|
---|
[128] | 1020 | /*@ end vars *************************************************** */
|
---|
[1] | 1021 |
|
---|
[1080] | 1022 | tempblock = (char *) mr_malloc((size_t) TAPE_BLOCK_SIZE);
|
---|
[1] | 1023 |
|
---|
[128] | 1024 | for (i = 0; i < (int) TAPE_BLOCK_SIZE; i++) {
|
---|
| 1025 | tempblock[i] = 0;
|
---|
| 1026 | }
|
---|
| 1027 | while (!(*pcontrol_char = tempblock[7000])) {
|
---|
| 1028 | g_tape_posK +=
|
---|
| 1029 | fread(tempblock, 1, (size_t) TAPE_BLOCK_SIZE,
|
---|
| 1030 | g_tape_stream) / 1024;
|
---|
| 1031 | }
|
---|
[1] | 1032 | /* memcpy((char*)plength_of_incoming_file,(char*)tempblock+7001,sizeof(long long)); */
|
---|
| 1033 | /* for(*plen=0,i=7;i>=0;i--) {*plen<<=8; *plen |= tempblock[7001+i];} */
|
---|
[128] | 1034 | memcpy((char *) plen, tempblock + 7001, sizeof(long long));
|
---|
| 1035 | if (strcmp(tempblock + 6000 + *pcontrol_char, "Mondolicious, baby")) {
|
---|
| 1036 | log_it("Bad header block at %ld K", (long) g_tape_posK);
|
---|
| 1037 | }
|
---|
| 1038 | strcpy(filename, tempblock + 1000);
|
---|
[1] | 1039 | /* strcpy(cksum,tempblock+5555);*/
|
---|
| 1040 | /* log_it( "%s (reading) fname=%s, filesize=%ld K",
|
---|
| 1041 | marker_to_string (*pcontrol_char), filename,
|
---|
| 1042 | (long) ((*plen) >> 10));
|
---|
| 1043 | */
|
---|
[128] | 1044 | if (*pcontrol_char == BLK_ABORTED_BACKUP) {
|
---|
| 1045 | log_to_screen("I can't verify an aborted backup.");
|
---|
| 1046 | retval = 1;
|
---|
| 1047 | } else {
|
---|
| 1048 | retval = 0;
|
---|
| 1049 | }
|
---|
| 1050 | for (i = 1000; i < 1020; i++) {
|
---|
| 1051 | if (tempblock[i] < 32 || tempblock[i] > 126) {
|
---|
| 1052 | tempblock[i] = ' ';
|
---|
| 1053 | }
|
---|
| 1054 | }
|
---|
| 1055 | tempblock[i] = '\0';
|
---|
[1107] | 1056 | mr_msg(6, "%s (fname=%s, size=%ld K)",
|
---|
[128] | 1057 | marker_to_string(*pcontrol_char), tempblock + 1000,
|
---|
| 1058 | (long) (*plen) >> 10);
|
---|
[1080] | 1059 | mr_free(tempblock);
|
---|
[128] | 1060 | return (retval);
|
---|
[1] | 1061 | }
|
---|
| 1062 |
|
---|
| 1063 |
|
---|
| 1064 |
|
---|
| 1065 | /**
|
---|
| 1066 | * Add specified file/slice to the internal catalog of all archives written.
|
---|
| 1067 | * This lets us restart on a new CD/tape/whatever if it runs out of room. We just
|
---|
| 1068 | * write the last [buffer size] MB from the catalog to the new tape, so we know
|
---|
| 1069 | * we have @e all archives on some CD/tape/whatever.
|
---|
| 1070 | * @param type The type of file we're cataloging (afioball, slice, something else)
|
---|
| 1071 | * @param number The fileset number or biggiefile number.
|
---|
| 1072 | * @param aux The slice number if it's a biggiefile, or any other additional info.
|
---|
| 1073 | * @param fn The original full pathname of the file we're recording.
|
---|
| 1074 | * @return The index of the record we just added.
|
---|
| 1075 | */
|
---|
[128] | 1076 | int register_in_tape_catalog(t_archtype type, int number, long aux,
|
---|
| 1077 | char *fn)
|
---|
[1] | 1078 | {
|
---|
[128] | 1079 | int last;
|
---|
| 1080 | char fname[MAX_TAPECAT_FNAME_LEN];
|
---|
| 1081 | char *p;
|
---|
[1] | 1082 |
|
---|
[128] | 1083 | p = strrchr(fn, '/');
|
---|
| 1084 | if (p) {
|
---|
| 1085 | p++;
|
---|
| 1086 | } else {
|
---|
| 1087 | p = fn;
|
---|
| 1088 | }
|
---|
| 1089 | strncpy(fname, p, MAX_TAPECAT_FNAME_LEN);
|
---|
| 1090 | fname[MAX_TAPECAT_FNAME_LEN] = '\0';
|
---|
| 1091 | last = g_tapecatalog->entries;
|
---|
| 1092 | if (last >= MAX_TAPECATALOG_ENTRIES) {
|
---|
| 1093 | log_it
|
---|
| 1094 | ("Warning - can't log #%d in tape catalog - too many entries already",
|
---|
| 1095 | number);
|
---|
| 1096 | return (-1);
|
---|
| 1097 | }
|
---|
| 1098 | g_tapecatalog->el[last].type = type;
|
---|
| 1099 | g_tapecatalog->el[last].number = number;
|
---|
| 1100 | g_tapecatalog->el[last].aux = aux;
|
---|
| 1101 | g_tapecatalog->el[last].tape_posK = g_tape_posK;
|
---|
| 1102 | strcpy(g_tapecatalog->el[last].fname, fname);
|
---|
| 1103 | g_tapecatalog->entries++;
|
---|
| 1104 | return (last); // returns the index of the record we've jsut added
|
---|
[1] | 1105 | }
|
---|
| 1106 |
|
---|
| 1107 |
|
---|
| 1108 |
|
---|
| 1109 |
|
---|
| 1110 | /**
|
---|
| 1111 | * Decide whether we should start a new tape. This is TRUE if we've run out of tape
|
---|
| 1112 | * (got SIGPIPE) or look like we will.
|
---|
| 1113 | * @param mediasize The size of the tape in megabytes.
|
---|
| 1114 | * @param length_of_incoming_file The length of the file we're about to write, in bytes.
|
---|
| 1115 | * @bug This seems like it'll only work for media_size != autodetect, but Mondo only allows
|
---|
| 1116 | * autodetecting the size. Huh?
|
---|
| 1117 | */
|
---|
[684] | 1118 |
|
---|
| 1119 | /* BERLIOS: Should be reviewed for mediasize being a off_t ??? */
|
---|
[1] | 1120 | bool
|
---|
[128] | 1121 | should_we_write_to_next_tape(long mediasize,
|
---|
[684] | 1122 | off_t length_of_incoming_file)
|
---|
[1] | 1123 | {
|
---|
[128] | 1124 | /*@ bool's ***************************************************** */
|
---|
| 1125 | bool we_need_a_new_tape = FALSE;
|
---|
[1] | 1126 |
|
---|
[128] | 1127 | /*@ end vars *************************************************** */
|
---|
[1] | 1128 |
|
---|
[128] | 1129 | if (mediasize == 0) {
|
---|
| 1130 | return (FALSE);
|
---|
| 1131 | }
|
---|
| 1132 | if (mediasize > 0 && (g_tape_posK >> 10 >= mediasize)) {
|
---|
| 1133 | log_it("mediasize = %ld", mediasize);
|
---|
| 1134 | we_need_a_new_tape = TRUE;
|
---|
[541] | 1135 | log_to_screen("Should have started a new tape/CD already");
|
---|
[128] | 1136 | }
|
---|
| 1137 | if ((g_tape_posK + length_of_incoming_file / 1024) >> 10 >=
|
---|
| 1138 | mediasize - (SLICE_SIZE * 4 / 1024)) {
|
---|
| 1139 | log_it("g_tape_posK = %ld\nmediasize = %ld\n", g_tape_posK,
|
---|
| 1140 | mediasize);
|
---|
| 1141 | we_need_a_new_tape = TRUE;
|
---|
| 1142 | }
|
---|
| 1143 | return (we_need_a_new_tape);
|
---|
[1] | 1144 | }
|
---|
| 1145 |
|
---|
| 1146 |
|
---|
| 1147 | /**
|
---|
| 1148 | * Seek through the stream until we find a header block where the NAME field matches
|
---|
| 1149 | * @p the_file_I_was_reading. This is useful if you've just started reading from
|
---|
| 1150 | * a new tape and want to find the file you were reading when the tape ended.
|
---|
| 1151 | * @param the_file_I_was_reading File name to look for.
|
---|
| 1152 | * @return 0 for success, nonzero for failure.
|
---|
| 1153 | */
|
---|
[128] | 1154 | int skip_incoming_files_until_we_find_this_one(char
|
---|
| 1155 | *the_file_I_was_reading)
|
---|
[1] | 1156 | {
|
---|
[128] | 1157 | char *pA;
|
---|
| 1158 | char *pB;
|
---|
| 1159 | int res;
|
---|
| 1160 | int ctrl_chr;
|
---|
| 1161 | char *temp_fname;
|
---|
| 1162 | char *datablock;
|
---|
| 1163 | long long temp_size, size;
|
---|
| 1164 | long bytes_to_write;
|
---|
[1] | 1165 |
|
---|
[1080] | 1166 | datablock = mr_malloc(TAPE_BLOCK_SIZE);
|
---|
[128] | 1167 | malloc_string(temp_fname);
|
---|
| 1168 | pB = strrchr(the_file_I_was_reading, '/');
|
---|
| 1169 | if (pB) {
|
---|
| 1170 | pB++;
|
---|
| 1171 | } else {
|
---|
| 1172 | pB = the_file_I_was_reading;
|
---|
[1] | 1173 | }
|
---|
[1107] | 1174 | mr_msg(1, "skip_incoming_..(%s)", pB);
|
---|
| 1175 | mr_msg(2, "Looking for initial START_AN_AFIO_OR_SLICE");
|
---|
[128] | 1176 | ctrl_chr = -1;
|
---|
| 1177 | while (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
|
---|
| 1178 | res =
|
---|
| 1179 | read_header_block_from_stream(&temp_size, temp_fname,
|
---|
| 1180 | &ctrl_chr);
|
---|
| 1181 | if (ctrl_chr == BLK_START_AN_AFIO_OR_SLICE) {
|
---|
| 1182 | break;
|
---|
| 1183 | }
|
---|
[1107] | 1184 | mr_msg(1, "%lld %s %c", temp_size, temp_fname, ctrl_chr);
|
---|
[128] | 1185 | wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
[1107] | 1186 | mr_msg(3, "Still trying to re-sync w/ tape");
|
---|
[128] | 1187 | }
|
---|
| 1188 | while (ctrl_chr != BLK_START_FILE) {
|
---|
| 1189 | res =
|
---|
| 1190 | read_header_block_from_stream(&temp_size, temp_fname,
|
---|
| 1191 | &ctrl_chr);
|
---|
| 1192 | if (ctrl_chr == BLK_START_FILE) {
|
---|
| 1193 | break;
|
---|
| 1194 | }
|
---|
[1107] | 1195 | mr_msg(1, "%lld %s %c", temp_size, temp_fname, ctrl_chr);
|
---|
[128] | 1196 | wrong_marker(BLK_START_FILE, ctrl_chr);
|
---|
[1107] | 1197 | mr_msg(3, "Still trying to re-sync w/ tape");
|
---|
[128] | 1198 | }
|
---|
| 1199 | pA = strrchr(temp_fname, '/');
|
---|
| 1200 | if (pA) {
|
---|
| 1201 | pA++;
|
---|
| 1202 | } else {
|
---|
| 1203 | pA = temp_fname;
|
---|
| 1204 | }
|
---|
| 1205 | pB = strrchr(the_file_I_was_reading, '/');
|
---|
| 1206 | if (pB) {
|
---|
| 1207 | pB++;
|
---|
| 1208 | } else {
|
---|
| 1209 | pB = the_file_I_was_reading;
|
---|
| 1210 | }
|
---|
| 1211 | while (strcmp(pA, pB)) {
|
---|
[1107] | 1212 | mr_msg(6, "Skipping %s (it's not %s)", temp_fname,
|
---|
[128] | 1213 | the_file_I_was_reading);
|
---|
| 1214 | for (size = temp_size; size > 0; size -= bytes_to_write) {
|
---|
| 1215 | bytes_to_write =
|
---|
| 1216 | (size < TAPE_BLOCK_SIZE) ? (long) size : TAPE_BLOCK_SIZE;
|
---|
| 1217 | // FIXME - needs error-checking and -catching
|
---|
| 1218 | fread(datablock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream);
|
---|
| 1219 | }
|
---|
| 1220 | res =
|
---|
| 1221 | read_header_block_from_stream(&temp_size, temp_fname,
|
---|
| 1222 | &ctrl_chr);
|
---|
| 1223 | if (ctrl_chr != BLK_STOP_FILE) {
|
---|
| 1224 | wrong_marker(BLK_STOP_FILE, ctrl_chr);
|
---|
| 1225 | }
|
---|
| 1226 | res =
|
---|
| 1227 | read_header_block_from_stream(&temp_size, temp_fname,
|
---|
| 1228 | &ctrl_chr);
|
---|
| 1229 | if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
|
---|
| 1230 | wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
| 1231 | }
|
---|
| 1232 | res =
|
---|
| 1233 | read_header_block_from_stream(&temp_size, temp_fname,
|
---|
| 1234 | &ctrl_chr);
|
---|
| 1235 | if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
|
---|
| 1236 | wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
|
---|
| 1237 | }
|
---|
| 1238 | res =
|
---|
| 1239 | read_header_block_from_stream(&temp_size, temp_fname,
|
---|
| 1240 | &ctrl_chr);
|
---|
| 1241 | if (ctrl_chr != BLK_START_FILE) {
|
---|
| 1242 | wrong_marker(BLK_START_FILE, ctrl_chr);
|
---|
| 1243 | }
|
---|
| 1244 | pA = strrchr(temp_fname, '/');
|
---|
| 1245 | if (pA) {
|
---|
| 1246 | pA++;
|
---|
| 1247 | } else {
|
---|
| 1248 | pA = temp_fname;
|
---|
| 1249 | }
|
---|
| 1250 | pB = strrchr(the_file_I_was_reading, '/');
|
---|
| 1251 | if (pB) {
|
---|
| 1252 | pB++;
|
---|
| 1253 | } else {
|
---|
| 1254 | pB = the_file_I_was_reading;
|
---|
| 1255 | }
|
---|
| 1256 | }
|
---|
[1107] | 1257 | mr_msg(2, "Reading %s (it matches %s)", temp_fname,
|
---|
[128] | 1258 | the_file_I_was_reading);
|
---|
[1080] | 1259 | mr_free(temp_fname);
|
---|
| 1260 | mr_free(datablock);
|
---|
[128] | 1261 | return (0);
|
---|
[1] | 1262 | }
|
---|
| 1263 |
|
---|
| 1264 |
|
---|
| 1265 | /**
|
---|
| 1266 | * Start to read from the next tape. Assumes the user has already inserted it.
|
---|
| 1267 | * @param bkpinfo The backup information structure. @c bkpinfo->media_device is the only field used.
|
---|
| 1268 | * @return 0 for success, nonzero for failure.
|
---|
| 1269 | */
|
---|
[128] | 1270 | int start_to_read_from_next_tape(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 1271 | {
|
---|
[128] | 1272 | /*@ int ********************************************************* */
|
---|
| 1273 | int res = 0;
|
---|
| 1274 | char *sz_msg;
|
---|
| 1275 | int ctrlchr;
|
---|
| 1276 | long long temp_size;
|
---|
| 1277 | malloc_string(sz_msg);
|
---|
| 1278 | /*@ end vars *************************************************** */
|
---|
[1] | 1279 |
|
---|
[128] | 1280 | paranoid_pclose(g_tape_stream);
|
---|
| 1281 | system("sync");
|
---|
| 1282 | system("sync");
|
---|
| 1283 | system("sync");
|
---|
| 1284 | log_it("Next tape requested.");
|
---|
| 1285 | insist_on_this_tape_number(g_current_media_number + 1); // will increment it, too
|
---|
| 1286 | log_it("Opening IN the next tape");
|
---|
| 1287 | if (!
|
---|
| 1288 | (g_tape_stream =
|
---|
| 1289 | open_device_via_buffer(bkpinfo->media_device, 'r',
|
---|
| 1290 | bkpinfo->internal_tape_block_size))) {
|
---|
| 1291 | log_OS_error(g_tape_fifo);
|
---|
[541] | 1292 | log_to_screen("Cannot openin stream device");
|
---|
[128] | 1293 | return (1);
|
---|
| 1294 | }
|
---|
| 1295 | g_tape_posK = 0;
|
---|
| 1296 | g_sigpipe = FALSE;
|
---|
| 1297 | res += read_header_block_from_stream(&temp_size, sz_msg, &ctrlchr); /* just in case */
|
---|
| 1298 | if (ctrlchr != BLK_START_OF_TAPE) {
|
---|
| 1299 | wrong_marker(BLK_START_OF_TAPE, ctrlchr);
|
---|
| 1300 | }
|
---|
| 1301 | res += read_header_block_from_stream(&temp_size, sz_msg, &ctrlchr); /* just in case */
|
---|
| 1302 | if (ctrlchr != BLK_START_OF_BACKUP) {
|
---|
| 1303 | wrong_marker(BLK_START_OF_BACKUP, ctrlchr);
|
---|
| 1304 | } else {
|
---|
[1107] | 1305 | mr_msg(3, "Next tape opened OK. Whoopee!");
|
---|
[128] | 1306 | }
|
---|
[1080] | 1307 | mr_free(sz_msg);
|
---|
[128] | 1308 | return (res);
|
---|
[1] | 1309 | }
|
---|
| 1310 |
|
---|
| 1311 |
|
---|
| 1312 |
|
---|
| 1313 | /**
|
---|
| 1314 | * Start to write to the next tape. Assume the user has already inserted it.
|
---|
| 1315 | * @param bkpinfo The backup information structure. @c bkpinfo->media_device is the only field used.
|
---|
| 1316 | * @return 0 for success, nonzero for failure.
|
---|
| 1317 | */
|
---|
[128] | 1318 | int start_to_write_to_next_tape(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 1319 | {
|
---|
[128] | 1320 | int res = 0;
|
---|
| 1321 | char command[MAX_STR_LEN * 2];
|
---|
| 1322 | paranoid_pclose(g_tape_stream);
|
---|
| 1323 | system("sync");
|
---|
| 1324 | system("sync");
|
---|
| 1325 | system("sync");
|
---|
| 1326 | log_it("New tape requested.");
|
---|
| 1327 | insist_on_this_tape_number(g_current_media_number + 1); // will increment g_current_media, too
|
---|
| 1328 | if (g_current_media_number > MAX_NOOF_MEDIA) {
|
---|
| 1329 | res++;
|
---|
[541] | 1330 | log_to_screen("Too many tapes. Man, you need to use nfs!");
|
---|
[1] | 1331 | }
|
---|
[128] | 1332 | if (bkpinfo->backup_media_type == cdstream) {
|
---|
| 1333 | sprintf(command,
|
---|
| 1334 | "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s",
|
---|
| 1335 | bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE,
|
---|
| 1336 | MONDO_LOGFILE);
|
---|
| 1337 | log_it("Opening OUT to next CD with the command");
|
---|
| 1338 | log_it(command);
|
---|
| 1339 | log_it("Let's see what happens, shall we?");
|
---|
| 1340 | g_tape_stream = popen(command, "w");
|
---|
| 1341 | if (!g_tape_stream) {
|
---|
[541] | 1342 | log_to_screen("Failed to openout to cdstream (fifo)");
|
---|
[128] | 1343 | return (1);
|
---|
| 1344 | }
|
---|
| 1345 | } else {
|
---|
| 1346 | log_it("Opening OUT to next tape");
|
---|
| 1347 | if (!
|
---|
| 1348 | (g_tape_stream =
|
---|
| 1349 | open_device_via_buffer(bkpinfo->media_device, 'w',
|
---|
| 1350 | bkpinfo->internal_tape_block_size))) {
|
---|
| 1351 | log_OS_error(g_tape_fifo);
|
---|
[541] | 1352 | log_to_screen("Cannot openin stream device");
|
---|
[128] | 1353 | return (1);
|
---|
| 1354 | }
|
---|
[1] | 1355 | }
|
---|
[128] | 1356 | g_tape_posK = 0;
|
---|
| 1357 | g_sigpipe = FALSE;
|
---|
[684] | 1358 | res += write_header_block_to_stream((off_t)0, "start-of-tape", BLK_START_OF_TAPE); /* just in case */
|
---|
| 1359 | res += write_header_block_to_stream((off_t)0, "start-of-backup", BLK_START_OF_BACKUP); /* just in case */
|
---|
[128] | 1360 | return (res);
|
---|
[1] | 1361 | }
|
---|
| 1362 |
|
---|
| 1363 |
|
---|
| 1364 |
|
---|
| 1365 |
|
---|
| 1366 | /**
|
---|
| 1367 | * Write a bufferfull of the most recent archives to the tape. The
|
---|
| 1368 | * rationale behind this is a bit complex. If the previous tape ended
|
---|
| 1369 | * suddenly (EOF or otherwise) some archives were probably left in the
|
---|
| 1370 | * buffer. That means that Mondo thinks they have been written, but
|
---|
| 1371 | * the external binary @c buffer has not actually written them. So to
|
---|
| 1372 | * be safe, we start the new tape by writing the last bufferfull from
|
---|
| 1373 | * the old one. This insures that all archives will be on at least
|
---|
| 1374 | * one tape. Sounds inelegant, but it works.
|
---|
| 1375 | * @param bkpinfo The backup information structure. @c bkpinfo->tmpdir is the only field used.
|
---|
| 1376 | * @return 0 for success, nonzero for failure.
|
---|
| 1377 | */
|
---|
[128] | 1378 | int write_backcatalog_to_tape(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 1379 | {
|
---|
[128] | 1380 | int i, last, res = 0;
|
---|
| 1381 | char *fname;
|
---|
[1] | 1382 |
|
---|
[1107] | 1383 | mr_msg(2, "I am now writing back catalog to tape");
|
---|
[128] | 1384 | malloc_string(fname);
|
---|
| 1385 | last = g_tapecatalog->entries - 1;
|
---|
| 1386 | for (i = 0; i <= last; i++) {
|
---|
| 1387 | sprintf(fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir,
|
---|
| 1388 | g_tapecatalog->el[i].fname);
|
---|
| 1389 | if (!does_file_exist(fname)) {
|
---|
[1107] | 1390 | mr_msg(6, "Can't write %s - it doesn't exist.", fname);
|
---|
[128] | 1391 | } else {
|
---|
| 1392 | write_header_block_to_stream(length_of_file(fname),
|
---|
| 1393 | "start-backcatalog-afio-or-slice",
|
---|
| 1394 | BLK_START_AN_AFIO_OR_SLICE);
|
---|
[1107] | 1395 | mr_msg(2, "Writing %s", fname);
|
---|
[128] | 1396 | if (write_file_to_stream_from_file(bkpinfo, fname)) {
|
---|
| 1397 | res++;
|
---|
[1107] | 1398 | mr_msg(2, "%s failed", fname);
|
---|
[128] | 1399 | }
|
---|
| 1400 | if (i != last) {
|
---|
[684] | 1401 | write_header_block_to_stream((off_t)0,
|
---|
[128] | 1402 | "stop-backcatalog-afio-or-slice",
|
---|
| 1403 | BLK_STOP_AN_AFIO_OR_SLICE);
|
---|
| 1404 | }
|
---|
| 1405 | }
|
---|
| 1406 | }
|
---|
[1080] | 1407 | mr_free(fname);
|
---|
[1107] | 1408 | mr_msg(2, "Finished writing back catalog to tape");
|
---|
[128] | 1409 | return (res);
|
---|
[1] | 1410 | }
|
---|
| 1411 |
|
---|
| 1412 |
|
---|
| 1413 |
|
---|
| 1414 | /**
|
---|
| 1415 | * Write all.tar.gz (produced by Mindi) to the first 32M of the first tape.
|
---|
| 1416 | * @param fname The path to all.tar.gz.
|
---|
| 1417 | * @return 0 for success, nonzero for failure.
|
---|
| 1418 | */
|
---|
[128] | 1419 | int write_data_disks_to_stream(char *fname)
|
---|
[1] | 1420 | {
|
---|
[128] | 1421 | /*@ pointers *************************************************** */
|
---|
| 1422 | FILE *fin;
|
---|
| 1423 | char tmp[MAX_STR_LEN];
|
---|
[1] | 1424 |
|
---|
[128] | 1425 | /*@ long ******************************************************* */
|
---|
| 1426 | long m = -1;
|
---|
| 1427 | long templong;
|
---|
[1] | 1428 |
|
---|
[128] | 1429 | /*@ int ******************************************************** */
|
---|
| 1430 | int i, j;
|
---|
[1] | 1431 |
|
---|
[128] | 1432 | /*@ buffers **************************************************** */
|
---|
| 1433 | char tempblock[256 * 1024];
|
---|
[1] | 1434 |
|
---|
[128] | 1435 | /*@ end vars *************************************************** */
|
---|
[1] | 1436 |
|
---|
[541] | 1437 | open_evalcall_form("Writing data disks to tape");
|
---|
| 1438 | log_to_screen("Writing data disks to tape");
|
---|
[128] | 1439 | log_it("Data disks = %s", fname);
|
---|
| 1440 | if (!does_file_exist(fname)) {
|
---|
[541] | 1441 | sprintf(tmp, "Cannot find %s", fname);
|
---|
[128] | 1442 | log_to_screen(tmp);
|
---|
| 1443 | return (1);
|
---|
[1] | 1444 | }
|
---|
[128] | 1445 | if (!(fin = fopen(fname, "r"))) {
|
---|
| 1446 | log_OS_error(fname);
|
---|
| 1447 | fatal_error("Cannot openin the data disk");
|
---|
| 1448 | }
|
---|
| 1449 | for (i = 0; i < 32; i++) { /* 32MB */
|
---|
| 1450 | for (j = 0; j < 4; j++) { /* 256K x 4 = 1MB (1024K) */
|
---|
| 1451 | if (!feof(fin)) {
|
---|
| 1452 | m = (long) fread(tempblock, 1, 256 * 1024, fin);
|
---|
| 1453 | } else {
|
---|
| 1454 | m = 0;
|
---|
| 1455 | }
|
---|
| 1456 | for (; m < 256 * 1024; m++) {
|
---|
| 1457 | tempblock[m] = '\0';
|
---|
| 1458 | }
|
---|
| 1459 | g_tape_posK +=
|
---|
| 1460 | fwrite(tempblock, 1, 256 * 1024, g_tape_stream) / 1024;
|
---|
| 1461 | }
|
---|
| 1462 | if (i > g_tape_buffer_size_MB) // otherwise, 'buffer' distorts calculations
|
---|
| 1463 | {
|
---|
| 1464 | templong = ((i - 8) * 4 + j) * 100 / (128 - 8 * 4);
|
---|
| 1465 | update_evalcall_form((int) (templong));
|
---|
| 1466 | }
|
---|
| 1467 | }
|
---|
| 1468 | paranoid_fclose(fin);
|
---|
| 1469 | close_evalcall_form();
|
---|
| 1470 | return (0);
|
---|
[1] | 1471 | }
|
---|
| 1472 |
|
---|
| 1473 |
|
---|
| 1474 |
|
---|
| 1475 |
|
---|
| 1476 | /**
|
---|
| 1477 | * Copy @p infile to the opened stream (CD or tape).
|
---|
| 1478 | * @param bkpinfo The backup information structure. @c bkpinfo->media_size is the only field used.
|
---|
| 1479 | * @param infile The file to write to the stream.
|
---|
| 1480 | * @return 0 for success, nonzero for failure.
|
---|
| 1481 | */
|
---|
[128] | 1482 | int write_file_to_stream_from_file(struct s_bkpinfo *bkpinfo, char *infile)
|
---|
[1] | 1483 | {
|
---|
[128] | 1484 | /*@ buffers **************************************************** */
|
---|
| 1485 | char tmp[MAX_STR_LEN];
|
---|
| 1486 | char datablock[TAPE_BLOCK_SIZE];
|
---|
| 1487 | char checksum[MAX_STR_LEN];
|
---|
| 1488 | char *infile_basename;
|
---|
[1] | 1489 |
|
---|
[128] | 1490 | /*@ int ******************************************************** */
|
---|
| 1491 | int retval = 0;
|
---|
| 1492 | int noof_blocks;
|
---|
[1] | 1493 |
|
---|
[128] | 1494 | /* unsigned int ch; */
|
---|
| 1495 | unsigned int crc16;
|
---|
| 1496 | unsigned int crctt;
|
---|
[1] | 1497 |
|
---|
[128] | 1498 | /*@ pointers *************************************************** */
|
---|
| 1499 | FILE *fin;
|
---|
| 1500 | char *p;
|
---|
[1] | 1501 |
|
---|
[128] | 1502 | /*@ long ******************************************************* */
|
---|
| 1503 | long bytes_to_read = 0;
|
---|
| 1504 | long i;
|
---|
[1] | 1505 |
|
---|
[684] | 1506 | off_t filesize;
|
---|
[1] | 1507 |
|
---|
| 1508 | #ifdef EXTRA_TAPE_CHECKSUMS
|
---|
[128] | 1509 | int ch;
|
---|
[1] | 1510 | #endif
|
---|
| 1511 |
|
---|
[128] | 1512 | /*@ initialize ************************************************ */
|
---|
| 1513 | crc16 = 0;
|
---|
| 1514 | crctt = 0;
|
---|
[1] | 1515 |
|
---|
| 1516 |
|
---|
| 1517 |
|
---|
[128] | 1518 | /*@ end vars *************************************************** */
|
---|
[1] | 1519 |
|
---|
[128] | 1520 | infile_basename = strrchr(infile, '/');
|
---|
| 1521 | if (infile_basename) {
|
---|
| 1522 | infile_basename++;
|
---|
| 1523 | } else {
|
---|
| 1524 | infile_basename = infile;
|
---|
| 1525 | }
|
---|
| 1526 | filesize = length_of_file(infile);
|
---|
| 1527 | if (should_we_write_to_next_tape
|
---|
| 1528 | (bkpinfo->media_size[g_current_media_number], filesize)) {
|
---|
| 1529 | start_to_write_to_next_tape(bkpinfo);
|
---|
| 1530 | write_backcatalog_to_tape(bkpinfo);
|
---|
| 1531 | }
|
---|
| 1532 | p = strrchr(infile, '/');
|
---|
| 1533 | if (!p) {
|
---|
| 1534 | p = infile;
|
---|
| 1535 | } else {
|
---|
| 1536 | p++;
|
---|
| 1537 | }
|
---|
| 1538 | sprintf(tmp, "Writing file '%s' to tape (%ld KB)", p,
|
---|
| 1539 | (long) filesize >> 10);
|
---|
| 1540 | log_it(tmp);
|
---|
| 1541 | write_header_block_to_stream(filesize, infile_basename,
|
---|
| 1542 | BLK_START_FILE);
|
---|
[1] | 1543 | //go_here_to_restart_saving_of_file:
|
---|
[128] | 1544 | if (!(fin = fopen(infile, "r"))) {
|
---|
| 1545 | log_OS_error(infile);
|
---|
| 1546 | return (1);
|
---|
[1] | 1547 | }
|
---|
[128] | 1548 | for (noof_blocks = 0; filesize > 0;
|
---|
| 1549 | noof_blocks++, filesize -= bytes_to_read) {
|
---|
| 1550 | if (filesize < TAPE_BLOCK_SIZE) {
|
---|
| 1551 | bytes_to_read = (long) filesize;
|
---|
| 1552 | for (i = 0; i < TAPE_BLOCK_SIZE; i++) {
|
---|
| 1553 | datablock[i] = '\0';
|
---|
| 1554 | }
|
---|
| 1555 | } else {
|
---|
| 1556 | bytes_to_read = TAPE_BLOCK_SIZE;
|
---|
| 1557 | }
|
---|
| 1558 | (void) fread(datablock, 1, (size_t) bytes_to_read, fin);
|
---|
| 1559 | g_tape_posK +=
|
---|
| 1560 | fwrite(datablock, 1, /*bytes_to_read */
|
---|
| 1561 | (size_t) TAPE_BLOCK_SIZE,
|
---|
| 1562 | g_tape_stream) / 1024;
|
---|
| 1563 | if (g_sigpipe) {
|
---|
| 1564 | iamhere("Sigpipe occurred recently. I'll start a new tape.");
|
---|
| 1565 | fclose(fin);
|
---|
| 1566 | g_sigpipe = FALSE;
|
---|
| 1567 | start_to_write_to_next_tape(bkpinfo);
|
---|
| 1568 | write_backcatalog_to_tape(bkpinfo); // kinda-sorta recursive :)
|
---|
| 1569 | return (0);
|
---|
| 1570 | }
|
---|
[1] | 1571 | #ifdef EXTRA_TAPE_CHECKSUMS
|
---|
[128] | 1572 | for (i = 0; i < bytes_to_read; i++) {
|
---|
| 1573 | ch = datablock[i];
|
---|
| 1574 | crc16 = updcrcr(crc16, (unsigned) ch);
|
---|
| 1575 | crctt = updcrc(crctt, (unsigned) ch);
|
---|
| 1576 | }
|
---|
[1] | 1577 | #endif
|
---|
[128] | 1578 | }
|
---|
| 1579 | paranoid_fclose(fin);
|
---|
| 1580 | sprintf(checksum, "%04x%04x", crc16, crctt);
|
---|
[684] | 1581 | /* BERLIOS: what does it do ??? */
|
---|
| 1582 | write_header_block_to_stream((off_t)g_current_media_number, checksum,
|
---|
[128] | 1583 | BLK_STOP_FILE);
|
---|
[1] | 1584 | // log_it("File '%s' written to tape.", infile);
|
---|
[128] | 1585 | return (retval);
|
---|
[1] | 1586 | }
|
---|
| 1587 |
|
---|
| 1588 |
|
---|
| 1589 |
|
---|
| 1590 |
|
---|
| 1591 |
|
---|
| 1592 | /**
|
---|
| 1593 | * Write a header block to the opened stream (CD or tape).
|
---|
| 1594 | * @param length_of_incoming_file The length to store in the header block.
|
---|
| 1595 | * Usually matters only if this is a file-related header, in which case it should
|
---|
| 1596 | * be the length of the file that will follow.
|
---|
| 1597 | * @param filename The filename to store in the header block. Usually matters
|
---|
| 1598 | * only if this is a file-related header, in which case this should be the name
|
---|
| 1599 | * if the file that will follow.
|
---|
| 1600 | * @param control_char The type of header block this is (start-file, end-file, start-tape, ...)
|
---|
| 1601 | * @return 0 for success, nonzero for failure.
|
---|
| 1602 | */
|
---|
| 1603 | int
|
---|
[684] | 1604 | write_header_block_to_stream(off_t length_of_incoming_file,
|
---|
[128] | 1605 | char *filename, int control_char)
|
---|
[1] | 1606 | {
|
---|
[128] | 1607 | /*@ buffers **************************************************** */
|
---|
| 1608 | char tempblock[TAPE_BLOCK_SIZE];
|
---|
| 1609 | char tmp[MAX_STR_LEN];
|
---|
| 1610 | char *p;
|
---|
[1] | 1611 |
|
---|
[128] | 1612 | /*@ int ******************************************************** */
|
---|
| 1613 | int i;
|
---|
[1] | 1614 |
|
---|
[684] | 1615 | off_t olen;
|
---|
[1] | 1616 |
|
---|
[128] | 1617 | /*@ end vars *************************************************** */
|
---|
[1] | 1618 |
|
---|
| 1619 |
|
---|
[128] | 1620 | olen = length_of_incoming_file;
|
---|
| 1621 | p = strrchr(filename, '/'); /* Make 'em go, "Unnnh!" Oh wait, that was _Master_ P... */
|
---|
| 1622 | if (!p) {
|
---|
| 1623 | p = filename;
|
---|
| 1624 | } else {
|
---|
| 1625 | p++;
|
---|
| 1626 | }
|
---|
| 1627 | if (!g_tape_stream) {
|
---|
| 1628 | log_to_screen
|
---|
[541] | 1629 | ("You're not backing up to tape. Why write a tape header?");
|
---|
[128] | 1630 | return (1);
|
---|
| 1631 | }
|
---|
| 1632 | for (i = 0; i < (int) TAPE_BLOCK_SIZE; i++) {
|
---|
| 1633 | tempblock[i] = 0;
|
---|
| 1634 | }
|
---|
| 1635 | sprintf(tempblock + 6000 + control_char, "Mondolicious, baby");
|
---|
| 1636 | tempblock[7000] = control_char;
|
---|
[1] | 1637 | /* for(i=0;i<8;i++) {tempblock[7001+i]=olen&0xff; olen>>=8;} */
|
---|
[684] | 1638 | memcpy(tempblock + 7001, (char *) &olen, sizeof(off_t));
|
---|
[1] | 1639 | /* if (length_of_incoming_file) {memcpy(tempblock+7001,(char*)&length_of_incoming_file,sizeof(long long));} */
|
---|
[128] | 1640 | strcpy(tempblock + 1000, filename);
|
---|
[1] | 1641 | /* strcpy(tempblock+5555,cksum); */
|
---|
[128] | 1642 | g_tape_posK +=
|
---|
| 1643 | fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE,
|
---|
| 1644 | g_tape_stream) / 1024;
|
---|
| 1645 | sprintf(tmp, "%s (fname=%s, size=%ld K)",
|
---|
| 1646 | marker_to_string(control_char), p,
|
---|
| 1647 | (long) length_of_incoming_file >> 10);
|
---|
[1107] | 1648 | mr_msg(6, tmp);
|
---|
[1] | 1649 | /* log_tape_pos(); */
|
---|
[128] | 1650 | return (0);
|
---|
[1] | 1651 | }
|
---|
| 1652 |
|
---|
| 1653 |
|
---|
| 1654 |
|
---|
| 1655 |
|
---|
| 1656 |
|
---|
| 1657 |
|
---|
| 1658 |
|
---|
| 1659 |
|
---|
| 1660 |
|
---|
| 1661 |
|
---|
| 1662 | /**
|
---|
| 1663 | * Log (to screen) an erroneous marker, along with what it should have been.
|
---|
| 1664 | * @param should_be What we were expecting.
|
---|
| 1665 | * @param it_is What we got.
|
---|
| 1666 | */
|
---|
[128] | 1667 | void wrong_marker(int should_be, int it_is)
|
---|
[1] | 1668 | {
|
---|
[128] | 1669 | /*@ buffer ***************************************************** */
|
---|
| 1670 | char tmp[MAX_STR_LEN];
|
---|
[1] | 1671 |
|
---|
| 1672 |
|
---|
[128] | 1673 | /*@ end vars *************************************************** */
|
---|
[541] | 1674 | sprintf(tmp, "Wrong marker! (Should be %s, ",
|
---|
[128] | 1675 | marker_to_string(should_be));
|
---|
[541] | 1676 | sprintf(tmp + strlen(tmp), "is actually %s)", marker_to_string(it_is));
|
---|
[128] | 1677 | log_to_screen(tmp);
|
---|
[1] | 1678 | }
|
---|
| 1679 |
|
---|
| 1680 | /* @} - end of streamGroup */
|
---|