Changeset 2d78d88 in mainline for uspace/app/fdisk/fdisk.c
- Timestamp:
- 2018-07-25T17:04:03Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- efa3136
- Parents:
- bec18a9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/fdisk/fdisk.c
rbec18a9 r2d78d88 65 65 /** Create logical partition */ 66 66 devac_create_log_part, 67 /** Modify partition */ 68 devac_modify_part, 67 69 /** Delete partition */ 68 70 devac_delete_part, … … 70 72 devac_exit 71 73 } devac_t; 74 75 /** Partition property to modify */ 76 typedef enum { 77 /** Modify mount point */ 78 pm_mountp, 79 /** Cancel */ 80 pm_cancel 81 } pmprop_t; 72 82 73 83 /** Confirm user selection. */ … … 507 517 } 508 518 509 /* Ask for mount point */510 tinput = tinput_new();511 if (tinput == NULL) {512 rc = ENOMEM;513 goto error;514 }515 516 rc = tinput_set_prompt(tinput, "?> ");517 if (rc != EOK)518 goto error;519 520 while (true) {521 printf("Enter mount point for new partition (Auto, None or /path).\n");522 rc = tinput_read_i(tinput, "Auto", &mountp);523 if (rc != EOK)524 goto error;525 526 rc = vol_mountp_validate(mountp);527 if (rc == EOK)528 break;529 530 free(mountp);531 mountp = NULL;532 }533 534 tinput_destroy(tinput);535 tinput = NULL;536 519 537 520 fdisk_pspec_init(&pspec); … … 560 543 } 561 544 562 static errno_t fdsk_delete_part(fdisk_dev_t *dev) 545 /** Add an option to choice for each partition. 546 * 547 * @param dev Fdisk device 548 * @param choice Choice to add optionts to 549 * 550 * @return EOK on sucess or error code 551 */ 552 static errno_t fdsk_add_part_choices(fdisk_dev_t *dev, 553 nchoice_t *choice) 563 554 { 564 nchoice_t *choice = NULL;565 555 fdisk_part_t *part; 566 556 fdisk_part_info_t pinfo; … … 570 560 char *sdesc = NULL; 571 561 const char *label; 572 bool confirm;573 void *sel;574 562 errno_t rc; 575 576 rc = nchoice_create(&choice);577 if (rc != EOK) {578 assert(rc == ENOMEM);579 printf("Out of memory.\n");580 goto error;581 }582 583 rc = nchoice_set_prompt(choice, "Select partition to delete");584 if (rc != EOK) {585 assert(rc == ENOMEM);586 printf("Out of memory.\n");587 goto error;588 }589 563 590 564 part = fdisk_part_first(dev); … … 656 630 } 657 631 658 rc = nchoice_add(choice, "Cancel", NULL, 0);659 if (rc != EOK) {660 assert(rc == ENOMEM);661 printf("Out of memory.\n");662 goto error;663 }664 665 rc = nchoice_get(choice, &sel);666 if (rc == ENOENT)667 return EOK;668 if (rc != EOK) {669 printf("Error getting user selection.\n");670 goto error;671 }672 673 674 nchoice_destroy(choice);675 choice = NULL;676 677 if (sel == NULL)678 return EOK;679 680 rc = fdsk_confirm("Warning. Any data in partition will be lost. "681 "Really delete partition?", &confirm);682 if (rc != EOK) {683 printf("Error getting user confirmation.\n");684 goto error;685 }686 687 if (!confirm)688 return EOK;689 690 rc = fdisk_part_destroy((fdisk_part_t *)sel);691 if (rc != EOK) {692 printf("Error deleting partition.\n");693 return rc;694 }695 696 632 return EOK; 697 633 error: … … 701 637 free(sdesc); 702 638 639 return rc; 640 } 641 642 /** Modify partition mount point. 643 * 644 * Run the interaction to modify a partition mount point 645 * 646 * @part Fdisk partition 647 * @return EOK on success or error code 648 */ 649 static errno_t fdsk_modify_mountp(fdisk_part_t *part) 650 { 651 tinput_t *tinput = NULL; 652 errno_t rc; 653 char *mountp = NULL; 654 655 /* Ask for mount point */ 656 tinput = tinput_new(); 657 if (tinput == NULL) { 658 rc = ENOMEM; 659 goto error; 660 } 661 662 rc = tinput_set_prompt(tinput, "?> "); 663 if (rc != EOK) 664 goto error; 665 666 while (true) { 667 printf("Enter mount point for new partition (Auto, None or /path).\n"); 668 rc = tinput_read_i(tinput, "Auto", &mountp); 669 if (rc != EOK) 670 goto error; 671 672 rc = vol_mountp_validate(mountp); 673 if (rc == EOK) 674 break; 675 676 free(mountp); 677 mountp = NULL; 678 } 679 680 rc = fdisk_part_set_mountp(part, mountp); 681 if (rc != EOK) 682 goto error; 683 684 free(mountp); 685 686 tinput_destroy(tinput); 687 tinput = NULL; 688 return EOK; 689 error: 690 if (mountp != NULL) 691 free(mountp); 692 if (tinput != NULL) 693 tinput_destroy(tinput); 694 return rc; 695 } 696 697 /** Modify partition. 698 * 699 * Run the interaction to modify a partition. 700 * 701 * @param dev Fdisk device 702 * @return EOK on success or error code 703 */ 704 static errno_t fdsk_modify_part(fdisk_dev_t *dev) 705 { 706 nchoice_t *choice = NULL; 707 fdisk_part_t *part; 708 void *sel; 709 errno_t rc; 710 711 rc = nchoice_create(&choice); 712 if (rc != EOK) { 713 assert(rc == ENOMEM); 714 printf("Out of memory.\n"); 715 goto error; 716 } 717 718 rc = nchoice_set_prompt(choice, "Select partition to modify"); 719 if (rc != EOK) { 720 assert(rc == ENOMEM); 721 printf("Out of memory.\n"); 722 goto error; 723 } 724 725 rc = fdsk_add_part_choices(dev, choice); 726 if (rc != EOK) 727 goto error; 728 729 rc = nchoice_add(choice, "Cancel", NULL, 0); 730 if (rc != EOK) { 731 assert(rc == ENOMEM); 732 printf("Out of memory.\n"); 733 goto error; 734 } 735 736 rc = nchoice_get(choice, &sel); 737 if (rc == ENOENT) 738 return EOK; 739 if (rc != EOK) { 740 printf("Error getting user selection.\n"); 741 goto error; 742 } 743 744 nchoice_destroy(choice); 745 choice = NULL; 746 747 if (sel == NULL) 748 return EOK; 749 750 part = (fdisk_part_t *)sel; 751 752 rc = nchoice_create(&choice); 753 if (rc != EOK) { 754 assert(rc == ENOMEM); 755 printf("Out of memory.\n"); 756 goto error; 757 } 758 759 rc = nchoice_set_prompt(choice, "Select property to modify"); 760 if (rc != EOK) { 761 assert(rc == ENOMEM); 762 printf("Out of memory.\n"); 763 goto error; 764 } 765 766 rc = nchoice_add(choice, "Mount point", (void *)pm_mountp, 0); 767 if (rc != EOK) { 768 assert(rc == ENOMEM); 769 printf("Out of memory.\n"); 770 goto error; 771 } 772 773 rc = nchoice_add(choice, "Cancel", (void *)pm_cancel, 0); 774 if (rc != EOK) { 775 assert(rc == ENOMEM); 776 printf("Out of memory.\n"); 777 goto error; 778 } 779 780 rc = nchoice_get(choice, &sel); 781 if (rc == ENOENT) 782 return EOK; 783 if (rc != EOK) { 784 printf("Error getting user selection.\n"); 785 goto error; 786 } 787 788 nchoice_destroy(choice); 789 choice = NULL; 790 791 switch ((pmprop_t)sel) { 792 case pm_mountp: 793 rc = fdsk_modify_mountp(part); 794 break; 795 case pm_cancel: 796 rc = EOK; 797 break; 798 } 799 800 return rc; 801 error: 802 if (choice != NULL) 803 nchoice_destroy(choice); 804 return rc; 805 } 806 807 static errno_t fdsk_delete_part(fdisk_dev_t *dev) 808 { 809 nchoice_t *choice = NULL; 810 bool confirm; 811 void *sel; 812 errno_t rc; 813 814 rc = nchoice_create(&choice); 815 if (rc != EOK) { 816 assert(rc == ENOMEM); 817 printf("Out of memory.\n"); 818 goto error; 819 } 820 821 rc = nchoice_set_prompt(choice, "Select partition to delete"); 822 if (rc != EOK) { 823 assert(rc == ENOMEM); 824 printf("Out of memory.\n"); 825 goto error; 826 } 827 828 rc = fdsk_add_part_choices(dev, choice); 829 if (rc != EOK) 830 goto error; 831 832 rc = nchoice_add(choice, "Cancel", NULL, 0); 833 if (rc != EOK) { 834 assert(rc == ENOMEM); 835 printf("Out of memory.\n"); 836 goto error; 837 } 838 839 rc = nchoice_get(choice, &sel); 840 if (rc == ENOENT) 841 return EOK; 842 if (rc != EOK) { 843 printf("Error getting user selection.\n"); 844 goto error; 845 } 846 847 848 nchoice_destroy(choice); 849 choice = NULL; 850 851 if (sel == NULL) 852 return EOK; 853 854 rc = fdsk_confirm("Warning. Any data in partition will be lost. " 855 "Really delete partition?", &confirm); 856 if (rc != EOK) { 857 printf("Error getting user confirmation.\n"); 858 goto error; 859 } 860 861 if (!confirm) 862 return EOK; 863 864 rc = fdisk_part_destroy((fdisk_part_t *)sel); 865 if (rc != EOK) { 866 printf("Error deleting partition.\n"); 867 return rc; 868 } 869 870 return EOK; 871 error: 703 872 if (choice != NULL) 704 873 nchoice_destroy(choice); … … 989 1158 } 990 1159 1160 if ((linfo.flags & lf_can_modify_part) != 0) { 1161 rc = nchoice_add(choice, "Modify partition", 1162 (void *)devac_modify_part, 0); 1163 if (rc != EOK) { 1164 assert(rc == ENOMEM); 1165 printf("Out of memory.\n"); 1166 goto error; 1167 } 1168 } 1169 991 1170 if ((linfo.flags & lf_can_delete_part) != 0) { 992 1171 rc = nchoice_add(choice, "Delete partition", … … 1061 1240 (void) fdsk_create_part(dev, lpk_logical); 1062 1241 break; 1242 case devac_modify_part: 1243 (void) fdsk_modify_part(dev); 1244 break; 1063 1245 case devac_delete_part: 1064 1246 (void) fdsk_delete_part(dev);
Note:
See TracChangeset
for help on using the changeset viewer.