| 209 | | char buffer[1024]; |
|---|
| 210 | | __u32 sect; |
|---|
| 211 | | int fo, fp; |
|---|
| 212 | | |
|---|
| 213 | | fo = open(device, O_WRONLY | O_LARGEFILE); |
|---|
| 214 | | sprintf(buffer, "/revosave/%s", fname); |
|---|
| 215 | | fp = open(buffer, O_RDONLY | O_LARGEFILE); |
|---|
| 216 | | |
|---|
| 217 | | while (1) { |
|---|
| 218 | | if (read(fp, buffer, 516) == 0) { |
|---|
| 219 | | break; |
|---|
| 220 | | } |
|---|
| 221 | | sect = *(__u32 *) buffer; |
|---|
| 222 | | if (lseek64(fo, (__u64)512 * (__off64_t) sect, SEEK_SET) == -1) { |
|---|
| 223 | | DEBUG(printf("restore_raw: seek error\n")); |
|---|
| 224 | | ui_seek_error(device, __LINE__, errno, fo, (__u64)512 * (__off64_t) sect); |
|---|
| 225 | | } |
|---|
| 226 | | if (write(fo, buffer+4, 512) != 512) { |
|---|
| 227 | | DEBUG(printf("restore_raw: write error\n")); |
|---|
| 228 | | ui_write_error(device, __LINE__, errno, fo); |
|---|
| 229 | | } |
|---|
| 230 | | } |
|---|
| 231 | | close(fp); |
|---|
| 232 | | if (ioctl(fo, BLKRRPART) < 0) { |
|---|
| 233 | | printf("Reloading partition table failed\n"); |
|---|
| 234 | | } |
|---|
| 235 | | close(fo); |
|---|
| | 236 | char buffer[1024]; |
|---|
| | 237 | __u32 sect; |
|---|
| | 238 | int fo, fp; |
|---|
| | 239 | |
|---|
| | 240 | fo = open(device, O_WRONLY | O_LARGEFILE); |
|---|
| | 241 | tmprintf("%s/%s", revosave, fname); |
|---|
| | 242 | fp = open(tmppath, O_RDONLY | O_LARGEFILE); |
|---|
| | 243 | |
|---|
| | 244 | while (1) { |
|---|
| | 245 | if (read(fp, buffer, 516) == 0) { |
|---|
| | 246 | break; |
|---|
| | 247 | } |
|---|
| | 248 | sect = *(__u32 *) buffer; |
|---|
| | 249 | if (lseek64(fo, (__u64) 512 * (__off64_t) sect, SEEK_SET) == -1) { |
|---|
| | 250 | DEBUG(printf("restore_raw: seek error\n")); |
|---|
| | 251 | ui_seek_error(device, __LINE__, errno, fo, |
|---|
| | 252 | (__u64) 512 * (__off64_t) sect); |
|---|
| | 253 | } |
|---|
| | 254 | if (write(fo, buffer + 4, 512) != 512) { |
|---|
| | 255 | DEBUG(printf("restore_raw: write error\n")); |
|---|
| | 256 | ui_write_error(device, __LINE__, errno, fo); |
|---|
| | 257 | } |
|---|
| | 258 | } |
|---|
| | 259 | close(fp); |
|---|
| | 260 | if (ioctl(fo, BLKRRPART) < 0) { |
|---|
| | 261 | myprintf("Reloading partition table failed\n"); |
|---|
| | 262 | } |
|---|
| | 263 | close(fo); |
|---|
| 286 | | char f[64], cmd[512]; |
|---|
| 287 | | struct stat st; |
|---|
| 288 | | |
|---|
| 289 | | sprintf(f, "%s%03d", fname, filenum); |
|---|
| 290 | | DEBUG (printf ("** File: %s **", f)); |
|---|
| 291 | | chdir("/tmpfs"); |
|---|
| 292 | | if (!nonewt) update_file(fname, filenum, -2, "Waiting", done); |
|---|
| 293 | | sprintf(cmd, "/bin/revowait %s", f); |
|---|
| 294 | | system(cmd); |
|---|
| 295 | | if (!nonewt) update_file(fname, filenum, -2, "Downloading", done); |
|---|
| 296 | | /* get files */ |
|---|
| 297 | | do |
|---|
| 298 | | { |
|---|
| 299 | | system("rm * >/dev/null 2>&1"); |
|---|
| 300 | | sprintf(cmd, "/bin/atftp --tftp-timeout 10 --option \"blksize 4096\" --option multicast -g -r %s/%s/%s %s 69 2>/tmp/atftp.log", servprefix, storagedir, f, servip); |
|---|
| | 316 | char f[64], cmd[512]; |
|---|
| | 317 | struct stat st; |
|---|
| | 318 | |
|---|
| | 319 | sprintf(f, "%s%03d", fname, filenum); |
|---|
| | 320 | DEBUG(printf("** File: %s **", f)); |
|---|
| | 321 | chdir("/tmpfs"); |
|---|
| | 322 | if (!nonewt) |
|---|
| | 323 | update_file(fname, filenum, -2, "Waiting", done); |
|---|
| | 324 | sprintf(cmd, "revowait %s", f); |
|---|
| | 325 | system(cmd); |
|---|
| | 326 | if (!nonewt) |
|---|
| | 327 | update_file(fname, filenum, -2, "Downloading", done); |
|---|
| | 328 | /* get files */ |
|---|
| | 329 | do { |
|---|
| | 330 | system("rm * >/dev/null 2>&1"); |
|---|
| | 331 | sprintf(cmd, |
|---|
| | 332 | "atftp --tftp-timeout 10 --option \"blksize 4096\" --option multicast -g -r %s/%s/%s %s 69 2>/tmp/atftp.log", |
|---|
| | 333 | servprefix, storagedir, f, servip); |
|---|
| 308 | | char f[64]; |
|---|
| 309 | | |
|---|
| 310 | | sprintf(f, "%s%03d", fname, filenum); |
|---|
| 311 | | return (fopen(f, "r")); |
|---|
| 312 | | } |
|---|
| 313 | | |
|---|
| 314 | | int tftp_close(FILE *stream) |
|---|
| 315 | | { |
|---|
| 316 | | int ret = fclose(stream); |
|---|
| 317 | | /* delete files */ |
|---|
| 318 | | //system("rm * >/dev/null 2>&1"); |
|---|
| 319 | | return ret; |
|---|
| 320 | | } |
|---|
| 321 | | |
|---|
| 322 | | /* |
|---|
| 323 | | */ |
|---|
| 324 | | int |
|---|
| 325 | | eof (int fd) |
|---|
| 326 | | { |
|---|
| 327 | | __off64_t pos, end; |
|---|
| 328 | | pos = lseek64 (fd, 0, SEEK_CUR); |
|---|
| 329 | | if (pos < 0) |
|---|
| 330 | | { |
|---|
| 331 | | fprintf (stderr, "Error LSEEK : eof,pos\n"); |
|---|
| 332 | | } |
|---|
| 333 | | end = lseek64 (fd, 0, SEEK_END); |
|---|
| 334 | | if (end < 0) |
|---|
| 335 | | { |
|---|
| 336 | | fprintf (stderr, "Error LSEEK : eof,end\n"); |
|---|
| 337 | | } |
|---|
| 338 | | if (lseek64 (fd, pos, SEEK_SET) < 0) |
|---|
| 339 | | { |
|---|
| 340 | | fprintf (stderr, "Error LSEEK, reseek\n"); |
|---|
| 341 | | } |
|---|
| 342 | | if (end == pos) |
|---|
| 343 | | return 1; |
|---|
| 344 | | return 0; |
|---|
| | 341 | char f[64]; |
|---|
| | 342 | |
|---|
| | 343 | sprintf(f, "%s%03d", fname, filenum); |
|---|
| | 344 | return (fopen(f, "r")); |
|---|
| | 345 | } |
|---|
| | 346 | |
|---|
| | 347 | int tftp_close(FILE * stream) |
|---|
| | 348 | { |
|---|
| | 349 | int ret = fclose(stream); |
|---|
| | 350 | |
|---|
| | 351 | return ret; |
|---|
| | 352 | } |
|---|
| | 353 | |
|---|
| | 354 | /* |
|---|
| | 355 | */ |
|---|
| | 356 | int eof(int fd) |
|---|
| | 357 | { |
|---|
| | 358 | __off64_t pos, end; |
|---|
| | 359 | pos = lseek64(fd, 0, SEEK_CUR); |
|---|
| | 360 | if (pos < 0) { |
|---|
| | 361 | fprintf(stderr, "Error LSEEK : eof,pos\n"); |
|---|
| | 362 | } |
|---|
| | 363 | end = lseek64(fd, 0, SEEK_END); |
|---|
| | 364 | if (end < 0) { |
|---|
| | 365 | fprintf(stderr, "Error LSEEK : eof,end\n"); |
|---|
| | 366 | } |
|---|
| | 367 | if (lseek64(fd, pos, SEEK_SET) < 0) { |
|---|
| | 368 | fprintf(stderr, "Error LSEEK, reseek\n"); |
|---|
| | 369 | } |
|---|
| | 370 | if (end == pos) |
|---|
| | 371 | return 1; |
|---|
| | 372 | return 0; |
|---|
| 351 | | fill (int fd, int bytes, int dir) |
|---|
| 352 | | { |
|---|
| 353 | | /* fills are not larger than 90MB so an 'int'should be enough */ |
|---|
| 354 | | int err = 0; |
|---|
| 355 | | |
|---|
| 356 | | if (lseek64 (fd, bytes, dir) < 0) |
|---|
| 357 | | { |
|---|
| 358 | | ui_write_error(__FILE__, __LINE__, errno, fd); |
|---|
| 359 | | err = 1; |
|---|
| 360 | | } |
|---|
| 361 | | } |
|---|
| 362 | | |
|---|
| 363 | | |
|---|
| 364 | | /* |
|---|
| 365 | | * |
|---|
| 366 | | */ |
|---|
| 367 | | void |
|---|
| 368 | | flushToDisk (unsigned char *buff, unsigned char *bit, PARAMS * cp, int lg) |
|---|
| 369 | | { |
|---|
| 370 | | unsigned char *ptr = buff; |
|---|
| 371 | | unsigned char mask[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; |
|---|
| 372 | | int indx = cp->bitindex; |
|---|
| 373 | | |
|---|
| | 394 | flushToDisk(unsigned char *buff, unsigned char *bit, PARAMS * cp, int lg) |
|---|
| | 395 | { |
|---|
| | 396 | unsigned char *ptr = buff; |
|---|
| | 397 | unsigned char mask[] = |
|---|
| | 398 | { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; |
|---|
| | 399 | int indx = cp->bitindex; |
|---|
| | 400 | |
|---|
| 391 | | if (cp->fo) |
|---|
| 392 | | { |
|---|
| 393 | | if (write (cp->fo, ptr, 512) != 512) |
|---|
| | 415 | if (cp->fo) { |
|---|
| | 416 | if (write(cp->fo, ptr, 512) != 512) { |
|---|
| | 417 | ui_write_error(__FILE__, __LINE__, errno, cp->fo); |
|---|
| | 418 | } |
|---|
| | 419 | } |
|---|
| | 420 | cp->offset += 512; |
|---|
| | 421 | ptr += 512; |
|---|
| | 422 | indx++; |
|---|
| | 423 | lg -= 512; |
|---|
| | 424 | } |
|---|
| | 425 | // printf("Exit : bitindex -> %d\n",indx); |
|---|
| | 426 | cp->bitindex = indx; |
|---|
| | 427 | } |
|---|
| | 428 | |
|---|
| | 429 | |
|---|
| | 430 | /* |
|---|
| | 431 | * |
|---|
| | 432 | */ |
|---|
| | 433 | void restore(char *device, unsigned int sect, char *fname) |
|---|
| | 434 | { |
|---|
| | 435 | int fo; /* output device */ |
|---|
| | 436 | z_stream zptr; |
|---|
| | 437 | int state, filenum, fmax = -1; |
|---|
| | 438 | int ret, firstpass, bitmaplg; |
|---|
| | 439 | FILE *fi; |
|---|
| | 440 | PARAMS currentparams; |
|---|
| | 441 | __u64 i, starto; |
|---|
| | 442 | |
|---|
| | 443 | currentparams.offset = 512 * (__u64) sect; |
|---|
| | 444 | currentparams.bitindex = 0; |
|---|
| | 445 | memset(zero, 0, 512); |
|---|
| | 446 | |
|---|
| | 447 | // log |
|---|
| | 448 | myprintf("restore: %s, offset %d sectors, %s\n", device, sect, fname); |
|---|
| | 449 | |
|---|
| | 450 | // open the output device |
|---|
| | 451 | fo = open(device, O_WRONLY | O_LARGEFILE); |
|---|
| | 452 | currentparams.fo = fo; |
|---|
| | 453 | DEBUG(printf("Seeking to : %lld\n", currentparams.offset)); |
|---|
| | 454 | i = lseek64(currentparams.fo, currentparams.offset, SEEK_SET); |
|---|
| | 455 | if (i != currentparams.offset) { |
|---|
| | 456 | ui_seek_error(__FILE__, __LINE__, errno, currentparams.fo, |
|---|
| | 457 | currentparams.offset); |
|---|
| | 458 | } |
|---|
| | 459 | // open the data directory |
|---|
| | 460 | filenum = 0; |
|---|
| | 461 | while (!fops.get(fname, filenum)) { |
|---|
| | 462 | /* name = ep->d_name; |
|---|
| | 463 | l = strlen(name); |
|---|
| | 464 | if (strncmp(name, fname, strlen(fname))) continue; |
|---|
| | 465 | if (l < 4) continue; |
|---|
| | 466 | if (!isdigit(name[l-1]) || !isdigit(name[l-2]) || !isdigit(name[l-3]) ) continue; |
|---|
| | 467 | DEBUG (printf ("** File: %s **", fname)); |
|---|
| | 468 | */ |
|---|
| | 469 | start: |
|---|
| | 470 | if (!nonewt) |
|---|
| | 471 | update_file(fname, filenum, fmax, device, done); |
|---|
| | 472 | |
|---|
| | 473 | state = Z_SYNC_FLUSH; |
|---|
| | 474 | firstpass = 1; |
|---|
| | 475 | bitmaplg = 0; |
|---|
| | 476 | |
|---|
| | 477 | zptr.zalloc = NULL; |
|---|
| | 478 | zptr.zfree = NULL; |
|---|
| | 479 | |
|---|
| | 480 | starto = lseek64(currentparams.fo, 0, SEEK_CUR); /* save the current offset */ |
|---|
| | 481 | |
|---|
| | 482 | fi = fops.open(fname, filenum); |
|---|
| | 483 | if (fi == NULL) { |
|---|
| | 484 | /*printf ("Cannot open input file\n"); */ |
|---|
| | 485 | system("/revobin/image_error \"Cannot open input file\""); |
|---|
| | 486 | fatal(); |
|---|
| | 487 | } |
|---|
| | 488 | |
|---|
| | 489 | zptr.avail_in = fread(IN, 1, INSIZE, fi); |
|---|
| | 490 | |
|---|
| | 491 | currentparams.offset = 0; |
|---|
| | 492 | currentparams.bitindex = 0; |
|---|
| | 493 | |
|---|
| | 494 | zptr.next_in = (unsigned char *) IN; |
|---|
| | 495 | zptr.next_out = (unsigned char *) BUFFER; // was dbuf.data; |
|---|
| | 496 | zptr.avail_out = 24064; |
|---|
| | 497 | |
|---|
| | 498 | inflateInit(&zptr); |
|---|
| | 499 | |
|---|
| | 500 | do { |
|---|
| | 501 | // if (inflateSyncPoint(&zptr)) printf("#"); |
|---|
| | 502 | |
|---|
| | 503 | ret = inflate(&zptr, state); |
|---|
| | 504 | if (!nonewt) |
|---|
| | 505 | update_progress(done + (zptr.total_in / 1024)); |
|---|
| | 506 | |
|---|
| | 507 | // printf("-> %d : %d / %d\n",ret ,zptr.avail_in ,zptr.avail_out ); |
|---|
| | 508 | |
|---|
| | 509 | if ((ret == Z_OK) && (zptr.avail_out == 0)) { |
|---|
| | 510 | if (firstpass) { |
|---|
| | 511 | DEBUG(printf("Params : *%s\n", BUFFER)); |
|---|
| | 512 | if (strstr(BUFFER, "BLOCKS=")) { |
|---|
| | 513 | int i = 0; |
|---|
| | 514 | if (sscanf(strstr(BUFFER, "BLOCKS=") + 7, "%d", &i) |
|---|
| | 515 | == 1) { |
|---|
| | 516 | fmax = i; |
|---|
| | 517 | } |
|---|
| | 518 | } |
|---|
| | 519 | if (strstr(BUFFER, "ALLOCTABLELG=")) |
|---|
| | 520 | sscanf(strstr(BUFFER, "ALLOCTABLELG=") + 13, "%d", |
|---|
| | 521 | &bitmaplg); |
|---|
| | 522 | memcpy(Bitmap, BUFFER + 2048, 24064 - 2048); |
|---|
| | 523 | currentparams.bitindex = 0; |
|---|
| | 524 | firstpass = 0; |
|---|
| | 525 | } else { |
|---|
| | 526 | flushToDisk(BUFFER, Bitmap, ¤tparams, 24064); |
|---|
| | 527 | } |
|---|
| | 528 | |
|---|
| | 529 | zptr.next_out = (unsigned char *) BUFFER; |
|---|
| | 530 | zptr.avail_out = 24064; |
|---|
| | 531 | } |
|---|
| | 532 | |
|---|
| | 533 | if ((ret == Z_OK) && (zptr.avail_in == 0)) { |
|---|
| | 534 | zptr.avail_in = fread(IN, 1, INSIZE, fi); |
|---|
| | 535 | zptr.next_in = (unsigned char *) IN; |
|---|
| | 536 | } |
|---|
| | 537 | } |
|---|
| | 538 | while (ret == Z_OK); |
|---|
| | 539 | |
|---|
| | 540 | if (ret == Z_STREAM_END) { |
|---|
| 395 | | ui_write_error(__FILE__, __LINE__, errno, cp->fo); |
|---|
| 396 | | } |
|---|
| 397 | | } |
|---|
| 398 | | cp->offset += 512; |
|---|
| 399 | | ptr += 512; |
|---|
| 400 | | indx++; |
|---|
| 401 | | lg -= 512; |
|---|
| 402 | | } |
|---|
| 403 | | // printf("Exit : bitindex -> %d\n",indx); |
|---|
| 404 | | cp->bitindex = indx; |
|---|
| 405 | | } |
|---|
| 406 | | |
|---|
| 407 | | |
|---|
| 408 | | /* |
|---|
| 409 | | * |
|---|
| 410 | | */ |
|---|
| 411 | | void restore(char *device, unsigned int sect, char *fname) |
|---|
| 412 | | { |
|---|
| 413 | | int fo; /* output device */ |
|---|
| 414 | | z_stream zptr; |
|---|
| 415 | | int state, filenum, fmax = -1; |
|---|
| 416 | | int ret, firstpass, bitmaplg; |
|---|
| 417 | | FILE *fi; |
|---|
| 418 | | PARAMS currentparams; |
|---|
| 419 | | __u64 i, starto; |
|---|
| 420 | | |
|---|
| 421 | | currentparams.offset = 512*(__u64)sect; |
|---|
| 422 | | currentparams.bitindex = 0; |
|---|
| 423 | | memset (zero, 0, 512); |
|---|
| 424 | | |
|---|
| 425 | | // log |
|---|
| 426 | | myprintf("restore: %s, offset %d sectors, %s\n", device, sect, fname); |
|---|
| 427 | | |
|---|
| 428 | | // open the output device |
|---|
| 429 | | fo = open(device, O_WRONLY | O_LARGEFILE ); |
|---|
| 430 | | currentparams.fo = fo; |
|---|
| 431 | | DEBUG(printf ("Seeking to : %lld\n", currentparams.offset)); |
|---|
| 432 | | i = lseek64 (currentparams.fo, currentparams.offset, SEEK_SET); |
|---|
| 433 | | if (i != currentparams.offset) { |
|---|
| 434 | | ui_seek_error(__FILE__, __LINE__, errno, currentparams.fo, currentparams.offset); |
|---|
| 435 | | } |
|---|
| 436 | | |
|---|
| 437 | | // open the data directory |
|---|
| 438 | | filenum = 0; |
|---|
| 439 | | while (!fops.get(fname ,filenum)) |
|---|
| 440 | | { |
|---|
| 441 | | /* name = ep->d_name; |
|---|
| 442 | | l = strlen(name); |
|---|
| 443 | | if (strncmp(name, fname, strlen(fname))) continue; |
|---|
| 444 | | if (l < 4) continue; |
|---|
| 445 | | if (!isdigit(name[l-1]) || !isdigit(name[l-2]) || !isdigit(name[l-3]) ) continue; |
|---|
| 446 | | DEBUG (printf ("** File: %s **", fname)); |
|---|
| 447 | | */ |
|---|
| 448 | | start: |
|---|
| 449 | | if (!nonewt) update_file(fname, filenum, fmax, device, done); |
|---|
| 450 | | |
|---|
| 451 | | state = Z_SYNC_FLUSH; |
|---|
| 452 | | firstpass = 1; |
|---|
| 453 | | bitmaplg = 0; |
|---|
| 454 | | |
|---|
| 455 | | zptr.zalloc = NULL; |
|---|
| 456 | | zptr.zfree = NULL; |
|---|
| 457 | | |
|---|
| 458 | | starto = lseek64(currentparams.fo, 0 , SEEK_CUR); /* save the current offset */ |
|---|
| 459 | | |
|---|
| 460 | | fi = fops.open (fname, filenum); |
|---|
| 461 | | if (fi == NULL) |
|---|
| 462 | | { |
|---|
| 463 | | /*printf ("Cannot open input file\n");*/ |
|---|
| 464 | | system("/revobin/image_error \"Cannot open input file\""); |
|---|
| 465 | | fatal(); |
|---|
| 466 | | } |
|---|
| 467 | | |
|---|
| 468 | | zptr.avail_in = fread (IN, 1, INSIZE, fi); |
|---|
| 469 | | |
|---|
| 470 | | currentparams.offset = 0; |
|---|
| 471 | | currentparams.bitindex = 0; |
|---|
| 472 | | |
|---|
| 473 | | zptr.next_in = (unsigned char *) IN; |
|---|
| 474 | | zptr.next_out = (unsigned char *) BUFFER; // was dbuf.data; |
|---|
| 475 | | zptr.avail_out = 24064; |
|---|
| 476 | | |
|---|
| 477 | | inflateInit (&zptr); |
|---|
| 478 | | |
|---|
| 479 | | do |
|---|
| 480 | | { |
|---|
| 481 | | // if (inflateSyncPoint(&zptr)) printf("#"); |
|---|
| 482 | | |
|---|
| 483 | | ret = inflate (&zptr, state); |
|---|
| 484 | | if (!nonewt) update_progress( done + (zptr.total_in/1024) ); |
|---|
| 485 | | |
|---|
| 486 | | // printf("-> %d : %d / %d\n",ret ,zptr.avail_in ,zptr.avail_out ); |
|---|
| 487 | | |
|---|
| 488 | | if ((ret == Z_OK) && (zptr.avail_out == 0)) |
|---|
| 489 | | { |
|---|
| 490 | | if (firstpass) |
|---|
| 491 | | { |
|---|
| 492 | | DEBUG (printf ("Params : *%s\n", BUFFER)); |
|---|
| 493 | | if (strstr (BUFFER, "BLOCKS=")) |
|---|
| 494 | | { |
|---|
| 495 | | int i = 0; |
|---|
| 496 | | if (sscanf (strstr (BUFFER, "BLOCKS=") + 7, "%d", &i) == 1) { |
|---|
| | 542 | if (firstpass) { |
|---|
| | 543 | DEBUG(printf("Params : *%s*\n", BUFFER)); |
|---|
| | 544 | if (strstr(BUFFER, "BLOCKS=")) { |
|---|
| | 545 | int i = 0; |
|---|
| | 546 | if (sscanf(strstr(BUFFER, "BLOCKS=") + 7, "%d", &i) |
|---|
| | 547 | == 1) { |
|---|
| 522 | | while (ret == Z_OK); |
|---|
| 523 | | |
|---|
| 524 | | if (ret == Z_STREAM_END) |
|---|
| 525 | | { |
|---|
| 526 | | { |
|---|
| 527 | | if (firstpass) |
|---|
| 528 | | { |
|---|
| 529 | | DEBUG (printf ("Params : *%s*\n", BUFFER)); |
|---|
| 530 | | if (strstr (BUFFER, "BLOCKS=")) |
|---|
| 531 | | { |
|---|
| 532 | | int i = 0; |
|---|
| 533 | | if (sscanf (strstr (BUFFER, "BLOCKS=") + 7, "%d", &i) == 1) { |
|---|
| 534 | | fmax = i; |
|---|
| 535 | | } |
|---|
| 536 | | } |
|---|
| 537 | | if (strstr (BUFFER, "ALLOCTABLELG=")) |
|---|
| 538 | | sscanf (strstr (BUFFER, "ALLOCTABLELG=") + 13, "%d", |
|---|
| 539 | | &bitmaplg); |
|---|
| 540 | | memcpy (Bitmap, BUFFER + 2048, 24064 - 2048); |
|---|
| 541 | | zptr.next_out = (unsigned char *) BUFFER; |
|---|
| 542 | | zptr.avail_out = 24064; |
|---|
| 543 | | } |
|---|
| 544 | | } |
|---|
| 545 | | |
|---|
| 546 | | //printf ("Flushing to EOF ... (%d bytes)\n", |
|---|
| 547 | | // 24064 - zptr.avail_out); |
|---|
| 548 | | flushToDisk (BUFFER, Bitmap, ¤tparams, 24064 - zptr.avail_out); |
|---|
| 549 | | zptr.next_out = (unsigned char *) BUFFER; |
|---|
| 550 | | zptr.avail_out = 24064; |
|---|
| 551 | | } |
|---|
| 552 | | |
|---|
| 553 | | ret = inflate (&zptr, Z_FINISH); |
|---|
| 554 | | inflateEnd (&zptr); |
|---|
| 555 | | |
|---|
| 556 | | |
|---|
| 557 | | if (ret < 0) |
|---|
| 558 | | { |
|---|
| 559 | | /*printf ("Returned : %d\t", ret); |
|---|
| 560 | | printf ("(AvailIn : %d / ", zptr.avail_in); |
|---|
| 561 | | printf ("AvailOut: %d)\n", zptr.avail_out); |
|---|
| 562 | | printf ("(TotalIn : %ld / ", zptr.total_in); |
|---|
| 563 | | printf ("TotalOut: %ld)\n", zptr.total_out);*/ |
|---|
| 564 | | ui_zlib_error(ret); |
|---|
| 565 | | fops.close (fi); |
|---|
| 566 | | fops.get(fname ,filenum); /* reget file */ |
|---|
| 567 | | /* return to the correct offset */ |
|---|
| 568 | | lseek64(currentparams.fo, starto , SEEK_SET); |
|---|
| 569 | | |
|---|
| 570 | | goto start; |
|---|
| 571 | | } |
|---|
| 572 | | |
|---|
| 573 | | /*printf ("Offset : %lld\n", currentparams.offset); |
|---|
| 574 | | printf ("Bitmap index : %d\n", currentparams.bitindex);*/ |
|---|
| 575 | | |
|---|
| 576 | | if (bitmaplg) |
|---|
| 577 | | { |
|---|
| 578 | | if (bitmaplg * 8 > currentparams.bitindex) |
|---|
| 579 | | { |
|---|
| 580 | | currentparams.offset += |
|---|
| 581 | | (__u64)512 * (bitmaplg * 8 - currentparams.bitindex); |
|---|
| 582 | | if (currentparams.fo) |
|---|
| 583 | | { |
|---|
| 584 | | /* no error check for the last fill */ |
|---|
| 585 | | /* bounds will be checked by the following write */ |
|---|
| 586 | | lseek64 (currentparams.fo, |
|---|
| 587 | | (__u64)512 * (bitmaplg * 8 - currentparams.bitindex), |
|---|
| 588 | | SEEK_CUR); |
|---|
| 589 | | } |
|---|
| | 559 | |
|---|
| | 560 | //printf ("Flushing to EOF ... (%d bytes)\n", |
|---|
| | 561 | // 24064 - zptr.avail_out); |
|---|
| | 562 | flushToDisk(BUFFER, Bitmap, ¤tparams, |
|---|
| | 563 | 24064 - zptr.avail_out); |
|---|
| | 564 | zptr.next_out = (unsigned char *) BUFFER; |
|---|
| | 565 | zptr.avail_out = 24064; |
|---|
| | 566 | } |
|---|
| | 567 | |
|---|
| | 568 | ret = inflate(&zptr, Z_FINISH); |
|---|
| | 569 | inflateEnd(&zptr); |
|---|
| | 570 | |
|---|
| | 571 | |
|---|
| | 572 | if (ret < 0) { |
|---|
| | 573 | /*printf ("Returned : %d\t", ret); |
|---|
| | 574 | printf ("(AvailIn : %d / ", zptr.avail_in); |
|---|
| | 575 | printf ("AvailOut: %d)\n", zptr.avail_out); |
|---|
| | 576 | printf ("(TotalIn : %ld / ", zptr.total_in); |
|---|
| | 577 | printf ("TotalOut: %ld)\n", zptr.total_out); */ |
|---|
| | 578 | ui_zlib_error(ret); |
|---|
| | 579 | fops.close(fi); |
|---|
| | 580 | fops.get(fname, filenum); /* reget file */ |
|---|
| | 581 | /* return to the correct offset */ |
|---|
| | 582 | lseek64(currentparams.fo, starto, SEEK_SET); |
|---|
| | 583 | |
|---|
| | 584 | goto start; |
|---|
| | 585 | } |
|---|
| | 586 | |
|---|
| | 587 | /*printf ("Offset : %lld\n", currentparams.offset); |
|---|
| | 588 | printf ("Bitmap index : %d\n", currentparams.bitindex); */ |
|---|
| | 589 | |
|---|
| | 590 | if (bitmaplg) { |
|---|
| | 591 | if (bitmaplg * 8 > currentparams.bitindex) { |
|---|
| | 592 | currentparams.offset += |
|---|
| | 593 | (__u64) 512 *(bitmaplg * 8 - currentparams.bitindex); |
|---|
| | 594 | if (currentparams.fo) { |
|---|
| | 595 | /* no error check for the last fill */ |
|---|
| | 596 | /* bounds will be checked by the following write */ |
|---|
| | 597 | lseek64(currentparams.fo, |
|---|
| | 598 | (__u64) 512 * (bitmaplg * 8 - |
|---|
| | 599 | currentparams.bitindex), |
|---|
| | 600 | SEEK_CUR); |
|---|
| 668 | | fclose(f); |
|---|
| 669 | | } |
|---|
| 670 | | |
|---|
| 671 | | void commandline(void) |
|---|
| 672 | | { |
|---|
| 673 | | unsigned char *ptr, *ptr2; |
|---|
| | 681 | fclose(f); |
|---|
| | 682 | } |
|---|
| | 683 | |
|---|
| | 684 | |
|---|
| | 685 | void setdefault(char *v) |
|---|
| | 686 | { |
|---|
| | 687 | char buf[256]; |
|---|
| | 688 | |
|---|
| | 689 | sprintf(buf, "revosetdefault %s", v != NULL ? v : "0"); |
|---|
| | 690 | system(buf); |
|---|
| | 691 | } |
|---|
| | 692 | |
|---|
| | 693 | /* |
|---|
| | 694 | * interprets the conf.txt file |
|---|
| | 695 | */ |
|---|
| | 696 | void restoreimage(void) |
|---|
| | 697 | { |
|---|
| | 698 | FILE *f; |
|---|
| | 699 | char buf[255], buf2[255], lvm[255]; |
|---|
| | 700 | int vgscan = 0; |
|---|
| | 701 | char *conftxt; |
|---|
| | 702 | |
|---|
| | 703 | if (cdrom) { |
|---|
| | 704 | conftxt = "/tmp/conf.txt"; |
|---|
| | 705 | } else { |
|---|
| | 706 | tmprintf("%s/conf.txt", revosave); |
|---|
| | 707 | conftxt = tmppath; |
|---|
| | 708 | } |
|---|
| | 709 | if ((f = fopen(conftxt, "r")) == NULL) |
|---|
| | 710 | return; |
|---|
| | 711 | while (!feof(f)) { |
|---|
| | 712 | fgets(buf, 250, f); |
|---|
| | 713 | if (sscanf(buf, "%s", buf2) == 1) { |
|---|
| | 714 | /* buf=full line, buf2=1st keyword */ |
|---|
| | 715 | DEBUG(printf("%s\n", buf2)); |
|---|
| | 716 | if (!strcmp("ptabs", buf2)) { |
|---|
| | 717 | // ptabs command |
|---|
| | 718 | unsigned int d1; |
|---|
| | 719 | |
|---|
| | 720 | if (sscanf(buf, " ptabs (hd%u) (nd)PATH/%s", &d1, buf2) == |
|---|
| | 721 | 2) { |
|---|
| | 722 | DEBUG(printf("%d,%s\n", d1, buf2)); |
|---|
| | 723 | // restore the files to the device |
|---|
| | 724 | #ifdef TEST |
|---|
| | 725 | //restore_raw("/revoinfo/PTABS", buf2); |
|---|
| | 726 | #else |
|---|
| | 727 | restore_raw(hdmap[d1], buf2); |
|---|
| | 728 | #endif |
|---|
| | 729 | } |
|---|
| | 730 | |
|---|
| | 731 | } else if (!strcmp("partcopy", buf2)) { |
|---|
| | 732 | // partcopy command |
|---|
| | 733 | unsigned int d1, d2, sect; |
|---|
| | 734 | #ifdef TEST_PARTONLY |
|---|
| | 735 | continue; |
|---|
| | 736 | #endif |
|---|
| | 737 | if (sscanf(buf, " partcopy (hd%u,%u) %u PATH/%s", |
|---|
| | 738 | &d1, &d2, §, buf2) == 4) { |
|---|
| | 739 | DEBUG(printf("%d,%d,%d,%s\n", d1, d2, sect, buf2)); |
|---|
| | 740 | // convert the BIOS hd number to a Linux device |
|---|
| | 741 | // and restore the files to the device |
|---|
| | 742 | if (d1 >= 3968 && d2 == -1) { |
|---|
| | 743 | // lvm: no hdmap necessary |
|---|
| | 744 | strncpy(lvm, "/dev/", 5); |
|---|
| | 745 | if (sscanf |
|---|
| | 746 | (buf, " partcopy (hd%*u,%*u) %*u PATH/%*s %s", |
|---|
| | 747 | &lvm[5]) != 1) { |
|---|
| | 748 | myprintf("syntax error in conf.txt: %s\n", |
|---|
| | 749 | buf); |
|---|
| | 750 | exit(1); |
|---|
| | 751 | } |
|---|
| | 752 | if (vgscan == 0) { |
|---|
| | 753 | system |
|---|
| | 754 | ("lvm vgscan >/dev/null 2>&1; lvm vgchange -ay >/dev/null 2>&1"); |
|---|
| | 755 | vgscan = 1; |
|---|
| | 756 | } |
|---|
| | 757 | DEBUG(printf("lvm : %s\n", lvm)); |
|---|
| | 758 | restore(lvm, sect, buf2); |
|---|
| | 759 | |
|---|
| | 760 | } else { |
|---|
| | 761 | #ifdef TEST |
|---|
| | 762 | // restore("/revoinfo/P1", sect, buf2); |
|---|
| | 763 | #else |
|---|
| | 764 | restore(hdmap[d1], sect, buf2); |
|---|
| | 765 | #endif |
|---|
| | 766 | // fix the NT Bootloader if needed |
|---|
| | 767 | if (sect == 63 && revontblfix == 1) { |
|---|
| | 768 | char command[255]; |
|---|
| | 769 | sprintf(command, "ntblfix %s %d", hdmap[d1], |
|---|
| | 770 | d1 + 1); |
|---|
| | 771 | mysystem(command); |
|---|
| | 772 | } |
|---|
| | 773 | } |
|---|
| | 774 | } |
|---|
| | 775 | } else if (!strcmp("setdefault", buf2) && !nolrs) { |
|---|
| | 776 | strtok(buf, " "); |
|---|
| | 777 | setdefault(strtok(NULL, " ")); |
|---|
| | 778 | } else if (!strcmp("chainloader", buf2) && !nolrs) { |
|---|
| | 779 | setdefault("0"); |
|---|
| | 780 | } |
|---|
| | 781 | } |
|---|
| | 782 | } |
|---|
| | 783 | fclose(f); |
|---|
| | 784 | } |
|---|
| | 785 | |
|---|
| | 786 | /* |
|---|
| | 787 | * Check if the image can fit |
|---|
| | 788 | */ |
|---|
| | 789 | void checkhdspace(__u32 major, __u32 minor, __u32 sect) |
|---|
| | 790 | { |
|---|
| | 791 | FILE *f; |
|---|
| | 792 | char command[256]; |
|---|
| | 793 | __u32 orig = 0; |
|---|
| | 794 | |
|---|
| | 795 | if (revonospc) |
|---|
| | 796 | return; |
|---|
| | 797 | |
|---|
| | 798 | tmprintf("%s/size%02x%02x.txt", revosave, major, minor); |
|---|
| | 799 | f = fopen(tmppath, "r"); |
|---|
| | 800 | if (f == NULL) |
|---|
| | 801 | return; |
|---|
| | 802 | fscanf(f, "%u", &orig); |
|---|
| | 803 | if (orig > sect) { |
|---|
| | 804 | /* problem : the disk seems to be too small */ |
|---|
| | 805 | if (!nolrs) |
|---|
| | 806 | system("revosendlog 8"); |
|---|
| | 807 | sprintf(command, |
|---|
| | 808 | "/revobin/image_error \"Your hard disk seems to be to small to restore this image (%u vs %u KB).\n\nIf you want to restore anyway, you can disable the disk space checks in the client's options panel.\"", |
|---|
| | 809 | sect, orig); |
|---|
| | 810 | system(command); |
|---|
| | 811 | while (1) |
|---|
| | 812 | sleep(1); |
|---|
| | 813 | } |
|---|
| | 814 | fclose(f); |
|---|
| | 815 | } |
|---|
| | 816 | |
|---|
| | 817 | /* |
|---|
| | 818 | * Build a BIOS number to device map |
|---|
| | 819 | * (should use the 'hdmap' file if present) |
|---|