Changeset 2d78d88 in mainline
- 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
- Location:
- uspace
- Files:
-
- 13 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); -
uspace/lib/c/generic/vol.c
rbec18a9 r2d78d88 338 338 } 339 339 340 /** Set mount point for partition. 341 * 342 * @param vol Volume service 343 * @param sid Partition service ID 344 * @param mountp Mount point 345 * 346 * @return EOK on success or an error code 347 */ 348 errno_t vol_part_set_mountp(vol_t *vol, service_id_t sid, 349 const char *mountp) 350 { 351 async_exch_t *exch; 352 ipc_call_t answer; 353 errno_t retval; 354 355 exch = async_exchange_begin(vol->sess); 356 aid_t req = async_send_1(exch, VOL_PART_SET_MOUNTP, sid, 357 &answer); 358 359 retval = async_data_write_start(exch, mountp, str_size(mountp)); 360 if (retval != EOK) { 361 async_exchange_end(exch); 362 async_forget(req); 363 return retval; 364 } 365 366 async_exchange_end(exch); 367 async_wait_for(req, &retval); 368 369 if (retval != EOK) 370 return retval; 371 372 return EOK; 373 } 374 340 375 /** Format file system type as string. 341 376 * -
uspace/lib/c/include/ipc/vol.h
rbec18a9 r2d78d88 46 46 VOL_PART_EMPTY, 47 47 VOL_PART_LSUPP, 48 VOL_PART_MKFS 48 VOL_PART_MKFS, 49 VOL_PART_SET_MOUNTP 49 50 } vol_request_t; 50 51 -
uspace/lib/c/include/types/label.h
rbec18a9 r2d78d88 86 86 lf_can_create_log = 0x10, 87 87 /** Currently it is possible to delete a partition */ 88 lf_can_delete_part = 0x20 88 lf_can_delete_part = 0x20, 89 /** Currently it is possible to modify a partition */ 90 lf_can_modify_part = 0x40 89 91 } label_flags_t; 90 92 -
uspace/lib/c/include/vol.h
rbec18a9 r2d78d88 53 53 extern errno_t vol_part_mkfs(vol_t *, service_id_t, vol_fstype_t, const char *, 54 54 const char *); 55 extern errno_t vol_part_set_mountp(vol_t *, service_id_t, const char *); 55 56 56 57 extern errno_t vol_fstype_format(vol_fstype_t, char **); -
uspace/lib/fdisk/include/fdisk.h
rbec18a9 r2d78d88 71 71 fdisk_part_t **); 72 72 extern errno_t fdisk_part_destroy(fdisk_part_t *); 73 extern errno_t fdisk_part_set_mountp(fdisk_part_t *, const char *); 73 74 extern void fdisk_pspec_init(fdisk_part_spec_t *); 74 75 -
uspace/lib/fdisk/src/fdisk.c
rbec18a9 r2d78d88 820 820 } 821 821 822 /** Set partition mount point. 823 * 824 * @param part Fdisk partition 825 * @param mountp Mount point 826 * 827 * @return EOK on success or error code 828 */ 829 errno_t fdisk_part_set_mountp(fdisk_part_t *part, const char *mountp) 830 { 831 return vol_part_set_mountp(part->dev->fdisk->vol, 832 part->svc_id, mountp); 833 } 834 822 835 void fdisk_pspec_init(fdisk_part_spec_t *pspec) 823 836 { -
uspace/lib/label/src/gpt.c
rbec18a9 r2d78d88 580 580 } 581 581 582 static bool gpt_can_modify_part(label_t *label) 583 { 584 return list_count(&label->parts) > 0; 585 } 586 582 587 static errno_t gpt_get_info(label_t *label, label_info_t *linfo) 583 588 { … … 589 594 if (gpt_can_delete_part(label)) 590 595 linfo->flags = linfo->flags | lf_can_delete_part; 596 if (gpt_can_modify_part(label)) 597 linfo->flags = linfo->flags | lf_can_modify_part; 591 598 linfo->ablock0 = label->ablock0; 592 599 linfo->anblocks = label->anblocks; -
uspace/lib/label/src/mbr.c
rbec18a9 r2d78d88 428 428 } 429 429 430 static bool mbr_can_modify_part(label_t *label) 431 { 432 return list_count(&label->parts) > 0; 433 } 434 435 430 436 static errno_t mbr_get_info(label_t *label, label_info_t *linfo) 431 437 { … … 448 454 if (mbr_can_delete_part(label)) 449 455 linfo->flags |= lf_can_delete_part; 456 /* Can modify partition */ 457 if (mbr_can_modify_part(label)) 458 linfo->flags |= lf_can_modify_part; 450 459 451 460 linfo->ablock0 = label->ablock0; -
uspace/lib/label/test/label.c
rbec18a9 r2d78d88 357 357 PCUT_ASSERT_INT_EQUALS(lt_mbr, linfo.ltype); 358 358 PCUT_ASSERT_INT_EQUALS(lf_ext_supp | lf_can_create_pri | 359 lf_can_create_ext | lf_can_delete_part, linfo.flags); 359 lf_can_create_ext | lf_can_delete_part | lf_can_modify_part, 360 linfo.flags); 360 361 361 362 part = label_part_first(label); … … 443 444 PCUT_ASSERT_INT_EQUALS(lt_mbr, linfo.ltype); 444 445 PCUT_ASSERT_INT_EQUALS(lf_ext_supp | lf_can_create_pri | 445 lf_can_create_log | lf_can_delete_part, linfo.flags); 446 lf_can_create_log | lf_can_delete_part | lf_can_modify_part, 447 linfo.flags); 446 448 447 449 epart = label_part_first(label); … … 586 588 PCUT_ASSERT_INT_EQUALS(lt_gpt, linfo.ltype); 587 589 PCUT_ASSERT_INT_EQUALS(lf_can_create_pri | lf_ptype_uuid | 588 lf_can_delete_part , linfo.flags);590 lf_can_delete_part | lf_can_modify_part, linfo.flags); 589 591 590 592 part = label_part_first(label); -
uspace/srv/volsrv/part.c
rbec18a9 r2d78d88 679 679 } 680 680 681 /** Set partition mount point. 682 * 683 * Set the partition mount point, (un-, re-)mounting the partition as necessary. 684 * 685 * @param part Partition 686 * @param mountp 687 * 688 * @return EOK on success or error code 689 */ 690 errno_t vol_part_set_mountp_part(vol_part_t *part, const char *mountp) 691 { 692 errno_t rc; 693 694 if (part->cur_mp != NULL) { 695 rc = vol_part_eject_part(part); 696 if (rc != EOK) 697 return rc; 698 } 699 700 rc = vol_part_mountp_set(part, mountp); 701 if (rc != EOK) 702 return rc; 703 704 rc = vol_part_mount(part); 705 if (rc != EOK) 706 return rc; 707 708 return EOK; 709 } 710 681 711 errno_t vol_part_get_info(vol_part_t *part, vol_part_info_t *pinfo) 682 712 { -
uspace/srv/volsrv/part.h
rbec18a9 r2d78d88 57 57 extern errno_t vol_part_mkfs_part(vol_part_t *, vol_fstype_t, const char *, 58 58 const char *); 59 extern errno_t vol_part_set_mountp_part(vol_part_t *, const char *); 59 60 extern errno_t vol_part_get_info(vol_part_t *, vol_part_info_t *); 60 61 -
uspace/srv/volsrv/volsrv.c
rbec18a9 r2d78d88 285 285 } 286 286 287 288 287 static void vol_part_mkfs_srv(vol_parts_t *parts, ipc_call_t *icall) 289 288 { … … 291 290 vol_part_t *part; 292 291 vol_fstype_t fstype; 293 char *label ;294 char *mountp ;292 char *label = NULL; 293 char *mountp = NULL; 295 294 errno_t rc; 296 295 … … 304 303 if (rc != EOK) { 305 304 async_answer_0(icall, rc); 306 return;305 goto error; 307 306 } 308 307 … … 315 314 0, NULL); 316 315 if (rc != EOK) { 317 free(label); 318 async_answer_0(icall, rc); 319 return; 316 async_answer_0(icall, rc); 317 goto error; 320 318 } 321 319 … … 327 325 rc = vol_part_find_by_id_ref(parts, sid, &part); 328 326 if (rc != EOK) { 327 async_answer_0(icall, ENOENT); 328 goto error; 329 } 330 331 rc = vol_part_mkfs_part(part, fstype, label, mountp); 332 if (rc != EOK) { 333 async_answer_0(icall, rc); 334 vol_part_del_ref(part); 335 goto error; 336 } 337 338 free(label); 339 free(mountp); 340 async_answer_0(icall, EOK); 341 342 return; 343 error: 344 if (label != NULL) 329 345 free(label); 346 if (mountp != NULL) 347 free(mountp); 348 } 349 350 static void vol_part_set_mountp_srv(vol_parts_t *parts, 351 ipc_call_t *icall) 352 { 353 service_id_t sid; 354 vol_part_t *part; 355 char *mountp; 356 errno_t rc; 357 358 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_set_mountp_srv()"); 359 360 sid = IPC_GET_ARG1(*icall); 361 362 rc = async_data_write_accept((void **)&mountp, true, 0, 363 VOL_MOUNTP_MAXLEN, 0, NULL); 364 if (rc != EOK) { 365 async_answer_0(icall, rc); 366 return; 367 } 368 369 if (mountp != NULL) { 370 log_msg(LOG_DEFAULT, LVL_NOTE, 371 "vol_part_set_mountp_srv: mountp='%s'", mountp); 372 } 373 374 rc = vol_part_find_by_id_ref(parts, sid, &part); 375 if (rc != EOK) { 376 free(mountp); 330 377 async_answer_0(icall, ENOENT); 331 378 return; 332 379 } 333 380 334 rc = vol_part_ mkfs_part(part, fstype, label, mountp);335 if (rc != EOK) { 336 free( label);381 rc = vol_part_set_mountp_part(part, mountp); 382 if (rc != EOK) { 383 free(mountp); 337 384 async_answer_0(icall, rc); 338 385 vol_part_del_ref(part); … … 340 387 } 341 388 342 free( label);389 free(mountp); 343 390 async_answer_0(icall, EOK); 344 391 } … … 386 433 vol_part_mkfs_srv(parts, &call); 387 434 break; 435 case VOL_PART_SET_MOUNTP: 436 vol_part_set_mountp_srv(parts, &call); 437 break; 388 438 default: 389 439 async_answer_0(&call, EINVAL);
Note:
See TracChangeset
for help on using the changeset viewer.