Changeset ea0ff6b in mainline
- 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
- Location:
- uspace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/fdisk/fdisk.c
redebb4a1 rea0ff6b 51 51 /** Delete label */ 52 52 devac_delete_label, 53 /** Erase disk */ 54 devac_erase_disk, 53 55 /** Create (primary) partition */ 54 56 devac_create_pri_part, … … 262 264 } 263 265 266 static int fdsk_erase_disk(fdisk_dev_t *dev) 267 { 268 int rc; 269 270 rc = fdisk_dev_erase(dev); 271 if (rc != EOK) { 272 printf("Error erasing disk.\n"); 273 return rc; 274 } 275 276 return EOK; 277 } 278 264 279 static int fdsk_select_fstype(vol_fstype_t *fstype) 265 280 { … … 473 488 fdisk_part_info_t pinfo; 474 489 fdisk_cap_t cap; 490 fdisk_dev_flags_t dflags; 475 491 char *sltype = NULL; 476 492 char *sdcap = NULL; … … 514 530 goto error; 515 531 } 532 533 fdisk_dev_get_flags(dev, &dflags); 516 534 517 535 printf("Device: %s, %s\n", sdcap, svcname); … … 667 685 } 668 686 669 if ( linfo.ltype == lt_none) {687 if ((dflags & fdf_can_create_label) != 0) { 670 688 rc = nchoice_add(choice, "Create label", 671 689 (void *)devac_create_label); … … 675 693 goto error; 676 694 } 677 } else { 695 } 696 697 if ((dflags & fdf_can_delete_label) != 0) { 678 698 rc = nchoice_add(choice, "Delete label", 679 699 (void *)devac_delete_label); 700 if (rc != EOK) { 701 assert(rc == ENOMEM); 702 printf("Out of memory.\n"); 703 goto error; 704 } 705 } 706 707 if ((dflags & fdf_can_erase_dev) != 0) { 708 rc = nchoice_add(choice, "Erase disk", 709 (void *)devac_erase_disk); 680 710 if (rc != EOK) { 681 711 assert(rc == ENOMEM); … … 704 734 case devac_delete_label: 705 735 (void) fdsk_delete_label(dev); 736 break; 737 case devac_erase_disk: 738 (void) fdsk_erase_disk(dev); 706 739 break; 707 740 case devac_create_pri_part: -
uspace/lib/c/generic/vol.c
redebb4a1 rea0ff6b 245 245 246 246 if (retval != EOK) 247 return EIO;247 return retval; 248 248 249 249 return EOK; -
uspace/lib/fdisk/include/fdisk.h
redebb4a1 rea0ff6b 52 52 extern int fdisk_dev_open(fdisk_t *, service_id_t, fdisk_dev_t **); 53 53 extern void fdisk_dev_close(fdisk_dev_t *); 54 extern int fdisk_dev_erase(fdisk_dev_t *); 55 extern void fdisk_dev_get_flags(fdisk_dev_t *, fdisk_dev_flags_t *); 54 56 extern int fdisk_dev_get_svcname(fdisk_dev_t *, char **); 55 57 extern int fdisk_dev_capacity(fdisk_dev_t *, fdisk_cap_t *); -
uspace/lib/fdisk/include/types/fdisk.h
redebb4a1 rea0ff6b 57 57 } fdisk_cunit_t; 58 58 59 /** Fdisk device flags */ 60 typedef enum { 61 /** Currently we can create a label */ 62 fdf_can_create_label = 0x1, 63 /** Currently we can delete the label */ 64 fdf_can_delete_label = 0x2, 65 /** Currently we can erase unknown data from disk */ 66 fdf_can_erase_dev = 0x4 67 } fdisk_dev_flags_t; 68 59 69 #define CU_LIMIT (cu_ybyte + 1) 60 70 … … 76 86 /** Link in fdisk_dev_list_t.devinfos */ 77 87 link_t ldevlist; 88 /** Service ID */ 78 89 service_id_t svcid; 79 90 /** Service name or NULL if not determined yet */ 80 91 char *svcname; 92 /** Device is initialized in libblock */ 81 93 bool blk_inited; 82 94 } fdisk_dev_info_t; -
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 } -
uspace/srv/volsrv/empty.c
redebb4a1 rea0ff6b 57 57 } 58 58 59 int vol_part_is_empty(service_id_t sid, bool *rempty) 60 { 61 int rc; 62 bool block_inited = false; 63 void *buf = NULL; 64 aoff64_t nblocks; 59 /** Calculate number of blocks to check. 60 * 61 * Will store to @a *ncb the number of blocks that should be checked 62 * at the beginning and end of device each. 63 * 64 * @param nblocks Total number of blocks on block device 65 * @param block_size Block size 66 * @param ncb Place to store number of blocks to check. 67 */ 68 static void calc_num_check_blocks(aoff64_t nblocks, size_t block_size, 69 aoff64_t *ncb) 70 { 65 71 aoff64_t n; 66 aoff64_t i;67 size_t block_size;68 bool empty;69 70 rc = block_init(EXCHANGE_SERIALIZE, sid, 2048);71 if (rc != EOK) {72 log_msg(LOG_DEFAULT, LVL_ERROR, "Error opening "73 "block device service %zu", sid);74 rc = EIO;75 goto error;76 }77 78 block_inited = true;79 80 rc = block_get_bsize(sid, &block_size);81 if (rc != EOK) {82 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting "83 "block size.");84 rc = EIO;85 goto error;86 }87 88 rc = block_get_nblocks(sid, &nblocks);89 if (rc != EOK) {90 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting "91 "number of blocks.");92 rc = EIO;93 goto error;94 }95 72 96 73 /* Check first 16 kiB / 16 blocks, whichever is more */ … … 104 81 if (n > (nblocks + 1) / 2) 105 82 n = (nblocks + 1) / 2; 83 84 *ncb = n; 85 } 86 87 int vol_part_is_empty(service_id_t sid, bool *rempty) 88 { 89 int rc; 90 bool block_inited = false; 91 void *buf = NULL; 92 aoff64_t nblocks; 93 aoff64_t n; 94 aoff64_t i; 95 size_t block_size; 96 bool empty; 97 98 rc = block_init(EXCHANGE_SERIALIZE, sid, 2048); 99 if (rc != EOK) { 100 log_msg(LOG_DEFAULT, LVL_ERROR, "Error opening " 101 "block device service %zu", sid); 102 rc = EIO; 103 goto error; 104 } 105 106 block_inited = true; 107 108 rc = block_get_bsize(sid, &block_size); 109 if (rc != EOK) { 110 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting " 111 "block size."); 112 rc = EIO; 113 goto error; 114 } 115 116 rc = block_get_nblocks(sid, &nblocks); 117 if (rc != EOK) { 118 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting " 119 "number of blocks."); 120 rc = EIO; 121 goto error; 122 } 123 124 calc_num_check_blocks(nblocks, block_size, &n); 106 125 107 126 buf = calloc(block_size, 1); … … 157 176 } 158 177 178 int vol_part_empty(service_id_t sid) 179 { 180 int rc; 181 bool block_inited = false; 182 void *buf = NULL; 183 aoff64_t nblocks; 184 aoff64_t n; 185 aoff64_t i; 186 size_t block_size; 187 188 rc = block_init(EXCHANGE_SERIALIZE, sid, 2048); 189 if (rc != EOK) { 190 log_msg(LOG_DEFAULT, LVL_ERROR, "Error opening " 191 "block device service %zu", sid); 192 rc = EIO; 193 goto error; 194 } 195 196 block_inited = true; 197 198 rc = block_get_bsize(sid, &block_size); 199 if (rc != EOK) { 200 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting " 201 "block size."); 202 rc = EIO; 203 goto error; 204 } 205 206 rc = block_get_nblocks(sid, &nblocks); 207 if (rc != EOK) { 208 log_msg(LOG_DEFAULT, LVL_ERROR, "Error getting " 209 "number of blocks."); 210 rc = EIO; 211 goto error; 212 } 213 214 calc_num_check_blocks(nblocks, block_size, &n); 215 216 buf = calloc(block_size, 1); 217 if (buf == NULL) { 218 log_msg(LOG_DEFAULT, LVL_ERROR, "Error allocating buffer."); 219 rc = ENOMEM; 220 goto error; 221 } 222 223 for (i = 0; i < n; i++) { 224 rc = block_write_direct(sid, i, 1, buf); 225 if (rc != EOK) { 226 log_msg(LOG_DEFAULT, LVL_ERROR, "Error " 227 "reading blocks."); 228 rc = EIO; 229 goto error; 230 } 231 } 232 233 for (i = 0; i < n; i++) { 234 rc = block_write_direct(sid, nblocks - n + i, 1, buf); 235 if (rc != EOK) { 236 log_msg(LOG_DEFAULT, LVL_ERROR, "Error " 237 "reading blocks."); 238 rc = EIO; 239 goto error; 240 } 241 } 242 243 block_fini(sid); 244 free(buf); 245 return EOK; 246 error: 247 if (block_inited) 248 block_fini(sid); 249 if (buf != NULL) 250 free(buf); 251 return rc; 252 } 253 159 254 /** @} 160 255 */ -
uspace/srv/volsrv/empty.h
redebb4a1 rea0ff6b 41 41 42 42 extern int vol_part_is_empty(service_id_t, bool *); 43 extern int vol_part_empty(service_id_t); 43 44 44 45 #endif -
uspace/srv/volsrv/part.c
redebb4a1 rea0ff6b 252 252 int vol_part_empty_part(vol_part_t *part) 253 253 { 254 int rc; 255 256 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_empty_part()"); 257 258 rc = vol_part_empty(part->svc_id); 259 if (rc != EOK) { 260 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_empty_part() - failed %d", 261 rc); 262 return rc; 263 } 264 265 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_empty_part() - success"); 254 266 part->pcnt = vpc_empty; 255 256 267 return EOK; 257 268 } -
uspace/srv/volsrv/volsrv.c
redebb4a1 rea0ff6b 199 199 200 200 sid = IPC_GET_ARG1(*icall); 201 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_empty_srv(%zu)", sid); 201 202 202 203 rc = vol_part_find_by_id(sid, &part); 203 204 if (rc != EOK) { 205 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_empty_srv(%zu) - " 206 "partition not found", sid); 204 207 async_answer_0(iid, ENOENT); 205 208 return; 206 209 } 207 210 211 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_empty_srv(%zu) - " 212 "call vol_part_empty_part()", sid); 208 213 rc = vol_part_empty_part(part); 209 214 if (rc != EOK) {
Note:
See TracChangeset
for help on using the changeset viewer.