Changeset ea0ff6b in mainline for uspace/lib/fdisk/src/fdisk.c
- Timestamp:
- 2015-10-15T20:43:30Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 44fe800
- Parents:
- edebb4a1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/fdisk/src/fdisk.c
redebb4a1 rea0ff6b 528 528 } 529 529 530 /** Erase contents of unlabeled disk. */ 531 int fdisk_dev_erase(fdisk_dev_t *dev) 532 { 533 fdisk_part_t *part; 534 int rc; 535 536 printf("fdisk_dev_erase.. check ltype\n"); 537 if (dev->dinfo.ltype != lt_none) 538 return EINVAL; 539 540 printf("fdisk_dev_erase.. get first part\n"); 541 part = fdisk_part_first(dev); 542 assert(part != NULL); 543 printf("fdisk_dev_erase.. check part\n"); 544 if (part->pcnt == vpc_empty) 545 return EINVAL; 546 547 printf("fdisk_dev_erase.. check part\n"); 548 rc = vol_part_empty(dev->fdisk->vol, part->svc_id); 549 if (rc != EOK) { 550 printf("vol_part_empty -> %d\n", rc); 551 return rc; 552 } 553 554 part->pcnt = vpc_empty; 555 return EOK; 556 } 557 558 void fdisk_dev_get_flags(fdisk_dev_t *dev, fdisk_dev_flags_t *rflags) 559 { 560 fdisk_dev_flags_t flags; 561 fdisk_part_t *part; 562 563 flags = 0; 564 565 /* fdf_can_create_label */ 566 if (dev->dinfo.ltype == lt_none) { 567 part = fdisk_part_first(dev); 568 assert(part != NULL); 569 if (part->pcnt == vpc_empty) 570 flags |= fdf_can_create_label; 571 else 572 flags |= fdf_can_erase_dev; 573 } else { 574 flags |= fdf_can_delete_label; 575 } 576 577 *rflags = flags; 578 } 579 530 580 int fdisk_dev_get_svcname(fdisk_dev_t *dev, char **rname) 531 581 { … … 587 637 int fdisk_label_create(fdisk_dev_t *dev, label_type_t ltype) 588 638 { 589 int rc; 639 fdisk_part_t *part; 640 int rc; 641 642 /* Disk must not contain a label. */ 643 if (dev->dinfo.ltype != lt_none) 644 return EEXIST; 645 646 /* Dummy partition spanning entire disk must be considered empty */ 647 part = fdisk_part_first(dev); 648 assert(part != NULL); 649 if (part->pcnt != vpc_empty) 650 return EEXIST; 590 651 591 652 /* Remove dummy partition */ … … 606 667 { 607 668 fdisk_part_t *part; 608 int rc; 669 fdisk_dev_flags_t dflags; 670 int rc; 671 672 printf("fdisk_label_destroy: begin\n"); 609 673 610 674 part = fdisk_part_first(dev); … … 616 680 } 617 681 682 printf("fdisk_label_destroy: vbd_label_delete\n"); 683 618 684 rc = vbd_label_delete(dev->fdisk->vbd, dev->sid); 619 685 if (rc != EOK) 620 686 return EIO; 621 687 688 printf("fdisk_label_destroy: add parts\n"); 622 689 rc = fdisk_dev_add_parts(dev); 623 690 if (rc != EOK) 624 691 return rc; 625 692 693 printf("fdisk_label_destroy: erase dev\n"); 694 /* Make sure device is considered empty */ 695 fdisk_dev_get_flags(dev, &dflags); 696 if ((dflags & fdf_can_erase_dev) != 0) { 697 rc = fdisk_dev_erase(dev); 698 if (rc != EOK) 699 return rc; 700 } 701 702 printf("fdisk_label_destroy: done\n"); 626 703 return EOK; 627 704 }
Note:
See TracChangeset
for help on using the changeset viewer.