Changeset 972 in MondoRescue
- Timestamp:
- Nov 23, 2006, 6:54:13 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/src/mondorestore/mondo-rstr-tools.c
r956 r972 383 383 **************************************************************************/ 384 384 385 /** 386 * Mount @p device at @p mpt as @p format. 387 * @param device The device (/dev entry) to mount. 388 * @param mpt The directory to mount it on. 389 * @param format The filesystem type of @p device. 390 * @param writeable If TRUE, mount read-write; if FALSE, mount read-only. 391 * @return 0 for success, nonzero for failure. 392 */ 393 int mount_device(char *device, char *mpt, char *format, bool writeable) 394 { 395 int res = 0; 396 397 char *tmp = NULL; 398 char *command = NULL; 399 char *mountdir = NULL; 400 char *mountpoint = NULL; 401 char *additional_parameters = NULL; 402 char *p1 = NULL; 403 char *p2 = NULL; 404 char *p3 = NULL; 405 406 assert_string_is_neither_NULL_nor_zerolength(device); 407 assert_string_is_neither_NULL_nor_zerolength(mpt); 408 assert(format != NULL); 409 410 if (!strcmp(mpt, "/1")) { 411 mr_asprintf(&mountpoint, "/"); 412 log_msg(3, "Mommm! SME is being a dildo!"); 413 } else { 414 mr_asprintf(&mountpoint, mpt); 415 } 416 417 if (!strcmp(mountpoint, "lvm")) { 418 mr_free(mountpoint); 419 return (0); 420 } 421 if (!strcmp(mountpoint, "image")) { 422 mr_free(mountpoint); 423 return (0); 424 } 425 mr_asprintf(&tmp, "Mounting device %s ", device); 426 log_msg(1, tmp); 427 428 if (writeable) { 429 mr_asprintf(&p1, "-o rw"); 430 } else { 431 mr_asprintf(&p1, "-o ro"); 432 } 433 tmp = find_home_of_exe("setfattr"); 434 if (tmp) { 435 mr_asprintf(&p2, ",user_xattr"); 436 } else { 437 mr_asprintf(&p2, "%s", ""); 438 } 439 mr_free(tmp); 440 441 tmp = find_home_of_exe("setfacl"); 442 if (tmp) { 443 mr_asprintf(&p3, ",acl"); 444 } else { 445 mr_asprintf(&p3, "%s", ""); 446 } 447 mr_free(tmp); 448 449 mr_asprintf(&additional_parameters, "%s%s%s", p1, p2, p3); 450 mr_free(p1); 451 mr_free(p2); 452 mr_free(p3); 453 454 if (!strcmp(mountpoint, "swap")) { 455 mr_asprintf(&command, "swapon %s", device); 456 } else { 457 if (!strcmp(mountpoint, "/")) { 458 mr_asprintf(&mountdir, MNT_RESTORING); 459 } else { 460 mr_asprintf(&mountdir, "%s%s", MNT_RESTORING, mountpoint); 461 } 462 mr_asprintf(&command, "mkdir -p %s", mountdir); 463 run_program_and_log_output(command, FALSE); 464 mr_free(command); 465 466 mr_asprintf(&command, "mount -t %s %s %s %s 2>> %s", format, device, 467 additional_parameters, mountdir, MONDO_LOGFILE); 468 log_msg(2, "command='%s'", command); 469 } 470 mr_free(additional_parameters); 471 472 res = run_program_and_log_output(command, TRUE); 473 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) { 474 log_msg(1, "Re-trying without the fancy extra parameters"); 475 mr_free(command); 476 477 mr_asprintf(&command, "mount -t %s %s %s 2>> %s", format, device, 478 mountdir, MONDO_LOGFILE); 479 res = run_program_and_log_output(command, TRUE); 480 } 481 if (res) { 482 log_msg(1, "Unable to mount device %s (type %s) at %s", device, 483 format, mountdir); 484 log_msg(1, "command was '%s'", command); 485 if (!strcmp(mountpoint, "swap")) { 486 log_to_screen(tmp); 487 } else { 488 log_msg(2, "Retrying w/o the '-t' switch"); 489 mr_free(command); 490 491 mr_asprintf(&command, "mount %s %s 2>> %s", device, mountdir, 492 MONDO_LOGFILE); 493 log_msg(2, "2nd command = '%s'", command); 494 res = run_program_and_log_output(command, TRUE); 495 if (res == 0) { 496 log_msg(1, 497 "That's OK. I called mount w/o a filesystem type and it worked fine in the end."); 498 } else { 499 log_to_screen(tmp); 500 } 501 } 502 } 503 mr_free(tmp); 504 mr_free(command); 505 mr_free(mountdir); 506 507 if (res && !strcmp(mountpoint, "swap")) { 508 log_msg(2, "That's ok. It's just a swap partition."); 509 log_msg(2, "Non-fatal error. Returning 0."); 510 res = 0; 511 } 512 mr_free(mountpoint); 513 514 return (res); 515 } 516 /************************************************************************** 517 *END_MOUNT_DEVICE * 518 **************************************************************************/ 519 520 385 521 386 522 /** … … 615 751 /************************************************************************** 616 752 *END_MOUNT_CDROM * 617 **************************************************************************/618 619 620 /**621 * Mount @p device at @p mpt as @p format.622 * @param device The device (/dev entry) to mount.623 * @param mpt The directory to mount it on.624 * @param format The filesystem type of @p device.625 * @param writeable If TRUE, mount read-write; if FALSE, mount read-only.626 * @return 0 for success, nonzero for failure.627 */628 int mount_device(char *device, char *mpt, char *format, bool writeable)629 {630 int res = 0;631 632 char *tmp = NULL;633 char *command = NULL;634 char *mountdir = NULL;635 char *mountpoint = NULL;636 char *additional_parameters = NULL;637 char *p1 = NULL;638 char *p2 = NULL;639 char *p3 = NULL;640 641 assert_string_is_neither_NULL_nor_zerolength(device);642 assert_string_is_neither_NULL_nor_zerolength(mpt);643 assert(format != NULL);644 645 if (!strcmp(mpt, "/1")) {646 mr_asprintf(&mountpoint, "/");647 log_msg(3, "Mommm! SME is being a dildo!");648 } else {649 mr_asprintf(&mountpoint, mpt);650 }651 652 if (!strcmp(mountpoint, "lvm")) {653 mr_free(mountpoint);654 return (0);655 }656 if (!strcmp(mountpoint, "image")) {657 mr_free(mountpoint);658 return (0);659 }660 mr_asprintf(&tmp, "Mounting device %s ", device);661 log_msg(1, tmp);662 663 if (writeable) {664 mr_asprintf(&p1, "-o rw");665 } else {666 mr_asprintf(&p1, "-o ro");667 }668 tmp = find_home_of_exe("setfattr");669 if (tmp) {670 mr_asprintf(&p2, ",user_xattr");671 } else {672 mr_asprintf(&p2, "%s", "");673 }674 mr_free(tmp);675 676 tmp = find_home_of_exe("setfacl");677 if (tmp) {678 mr_asprintf(&p3, ",acl");679 } else {680 mr_asprintf(&p3, "%s", "");681 }682 mr_free(tmp);683 684 mr_asprintf(&additional_parameters, "%s%s%s", p1, p2, p3);685 mr_free(p1);686 mr_free(p2);687 mr_free(p3);688 689 if (!strcmp(mountpoint, "swap")) {690 mr_asprintf(&command, "swapon %s", device);691 } else {692 if (!strcmp(mountpoint, "/")) {693 mr_asprintf(&mountdir, MNT_RESTORING);694 } else {695 mr_asprintf(&mountdir, "%s%s", MNT_RESTORING, mountpoint);696 }697 mr_asprintf(&command, "mkdir -p %s", mountdir);698 run_program_and_log_output(command, FALSE);699 mr_free(command);700 701 mr_asprintf(&command, "mount -t %s %s %s %s 2>> %s", format, device,702 additional_parameters, mountdir, MONDO_LOGFILE);703 log_msg(2, "command='%s'", command);704 }705 mr_free(additional_parameters);706 707 res = run_program_and_log_output(command, TRUE);708 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {709 log_msg(1, "Re-trying without the fancy extra parameters");710 mr_free(command);711 712 mr_asprintf(&command, "mount -t %s %s %s 2>> %s", format, device,713 mountdir, MONDO_LOGFILE);714 res = run_program_and_log_output(command, TRUE);715 }716 if (res) {717 log_msg(1, "Unable to mount device %s (type %s) at %s", device,718 format, mountdir);719 log_msg(1, "command was '%s'", command);720 if (!strcmp(mountpoint, "swap")) {721 log_to_screen(tmp);722 } else {723 log_msg(2, "Retrying w/o the '-t' switch");724 mr_free(command);725 726 mr_asprintf(&command, "mount %s %s 2>> %s", device, mountdir,727 MONDO_LOGFILE);728 log_msg(2, "2nd command = '%s'", command);729 res = run_program_and_log_output(command, TRUE);730 if (res == 0) {731 log_msg(1,732 "That's OK. I called mount w/o a filesystem type and it worked fine in the end.");733 } else {734 log_to_screen(tmp);735 }736 }737 }738 mr_free(tmp);739 mr_free(command);740 mr_free(mountdir);741 742 if (res && !strcmp(mountpoint, "swap")) {743 log_msg(2, "That's ok. It's just a swap partition.");744 log_msg(2, "Non-fatal error. Returning 0.");745 res = 0;746 }747 mr_free(mountpoint);748 749 return (res);750 }751 /**************************************************************************752 *END_MOUNT_DEVICE *753 753 **************************************************************************/ 754 754
Note:
See TracChangeset
for help on using the changeset viewer.