Changeset ef9dac04 in mainline
- Timestamp:
- 2015-10-22T20:21:03Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9854a8f
- Parents:
- 21f1543
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/fdisk/fdisk.c
r21f1543 ref9dac04 65 65 } devac_t; 66 66 67 /** Confirm user selection. */ 68 static int fdsk_confirm(const char *msg, bool *rconfirm) 69 { 70 tinput_t *tinput = NULL; 71 char *answer; 72 int rc; 73 74 tinput = tinput_new(); 75 if (tinput == NULL) { 76 rc = ENOMEM; 77 goto error; 78 } 79 80 rc = tinput_set_prompt(tinput, "y/n> "); 81 if (rc != EOK) 82 goto error; 83 84 while (true) { 85 printf("%s\n", msg); 86 87 rc = tinput_read(tinput, &answer); 88 if (rc == ENOENT) { 89 *rconfirm = false; 90 free(answer); 91 break; 92 } 93 94 if (rc != EOK) 95 goto error; 96 97 if (str_cmp(answer, "y") == 0) { 98 *rconfirm = true; 99 free(answer); 100 break; 101 } else if (str_cmp(answer, "n") == 0) { 102 *rconfirm = false; 103 free(answer); 104 break; 105 } 106 } 107 108 tinput_destroy(tinput); 109 return EOK; 110 error: 111 if (tinput != NULL) 112 tinput_destroy(tinput); 113 return rc; 114 } 115 67 116 /** Device selection */ 68 117 static int fdsk_dev_sel_choice(service_id_t *rsvcid) … … 254 303 static int fdsk_delete_label(fdisk_dev_t *dev) 255 304 { 305 bool confirm; 256 306 int rc; 307 308 rc = fdsk_confirm("Warning. Any data on disk will be lost. " 309 "Really delete label?", &confirm); 310 if (rc != EOK) { 311 printf("Error getting user confirmation.\n"); 312 return rc; 313 } 314 315 if (!confirm) 316 return EOK; 257 317 258 318 rc = fdisk_label_destroy(dev); … … 267 327 static int fdsk_erase_disk(fdisk_dev_t *dev) 268 328 { 329 bool confirm; 269 330 int rc; 331 332 rc = fdsk_confirm("Warning. Any data on disk will be lost. " 333 "Really erase disk?", &confirm); 334 if (rc != EOK) { 335 printf("Error getting user confirmation.\n"); 336 return rc; 337 } 338 339 if (!confirm) 340 return EOK; 270 341 271 342 rc = fdisk_dev_erase(dev); … … 422 493 char *sfstype = NULL; 423 494 char *sdesc = NULL; 495 bool confirm; 424 496 void *sel; 425 497 int rc; … … 507 579 508 580 rc = nchoice_get(choice, &sel); 581 if (rc == ENOENT) 582 return EOK; 509 583 if (rc != EOK) { 510 584 printf("Error getting user selection.\n"); … … 512 586 } 513 587 514 if (sel != NULL) {515 rc = fdisk_part_destroy((fdisk_part_t *)sel);516 if (rc != EOK) {517 printf("Error deleting partition.\n");518 return rc;519 }520 }521 588 522 589 nchoice_destroy(choice); 590 choice = NULL; 591 592 if (sel == NULL) 593 return EOK; 594 595 rc = fdsk_confirm("Warning. Any data in partition will be lost. " 596 "Really delete partition?", &confirm); 597 if (rc != EOK) { 598 printf("Error getting user confirmation.\n"); 599 goto error; 600 } 601 602 if (!confirm) 603 return EOK; 604 605 rc = fdisk_part_destroy((fdisk_part_t *)sel); 606 if (rc != EOK) { 607 printf("Error deleting partition.\n"); 608 return rc; 609 } 610 523 611 return EOK; 524 612 error:
Note:
See TracChangeset
for help on using the changeset viewer.