Changeset edebb4a1 in mainline
- Timestamp:
- 2015-10-14T22:30:12Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ea0ff6b
- Parents:
- 4b6635a7
- Location:
- uspace
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/fdisk/fdisk.c
r4b6635a7 redebb4a1 565 565 } 566 566 567 printf("Partition %d: %s", npart, scap); 567 if (linfo.ltype == lt_none) 568 printf("Entire disk: %s", scap); 569 else 570 printf("Partition %d: %s", npart, scap); 571 568 572 if ((linfo.flags & lf_ext_supp) != 0) { 569 573 rc = fdisk_pkind_format(pinfo.pkind, &spkind); … … 653 657 } 654 658 655 if ( npart >0) {659 if ((linfo.flags & lf_can_delete_part) != 0) { 656 660 rc = nchoice_add(choice, "Delete partition", 657 661 (void *)devac_delete_part); -
uspace/lib/c/generic/vol.c
r4b6635a7 redebb4a1 188 188 } 189 189 190 /** Add partition. 191 * 192 * After a partition is created (e.g. as a result of deleting a label 193 * the dummy partition is created), it can take some (unknown) time 194 * until it is discovered. 195 */ 196 int vol_part_add(vol_t *vol, service_id_t sid) 197 { 198 async_exch_t *exch; 199 int retval; 200 201 exch = async_exchange_begin(vol->sess); 202 retval = async_req_1_0(exch, VOL_PART_ADD, sid); 203 async_exchange_end(exch); 204 205 if (retval != EOK) 206 return retval; 207 208 return EOK; 209 } 210 190 211 /** Get partition information. */ 191 212 int vol_part_info(vol_t *vol, service_id_t sid, vol_part_info_t *vinfo) -
uspace/lib/c/include/ipc/vol.h
r4b6635a7 redebb4a1 38 38 typedef enum { 39 39 VOL_GET_PARTS = IPC_FIRST_USER_METHOD, 40 VOL_PART_ADD, 40 41 VOL_PART_INFO, 41 42 VOL_PART_EMPTY -
uspace/lib/c/include/types/label.h
r4b6635a7 redebb4a1 81 81 /** Currently it is possible to create an extended partition */ 82 82 lf_can_create_ext = 0x8, 83 /** Currrently it is possible to create a logical partition */ 84 lf_can_create_log = 0x10 83 /** Currently it is possible to create a logical partition */ 84 lf_can_create_log = 0x10, 85 /** Currently it is possible to delete a partition */ 86 lf_can_delete_part = 0x20 85 87 } label_flags_t; 86 88 -
uspace/lib/c/include/types/vol.h
r4b6635a7 redebb4a1 55 55 #define VOL_FSTYPE_LIMIT (fs_ext4 + 1) 56 56 57 /** Volume service */ 58 typedef struct vol { 59 /** Volume service session */ 60 async_sess_t *sess; 61 } vol_t; 62 63 /** Partition information */ 64 typedef struct { 65 /** Partition content type */ 66 vol_part_cnt_t pcnt; 67 /** Filesystem type */ 68 vol_fstype_t fstype; 69 } vol_part_info_t; 70 57 71 #endif 58 72 -
uspace/lib/c/include/vol.h
r4b6635a7 redebb4a1 42 42 #include <types/vol.h> 43 43 44 /** Volume service */45 typedef struct vol {46 /** Volume service session */47 async_sess_t *sess;48 } vol_t;49 50 /** Partition information */51 typedef struct {52 /** Partition content type */53 vol_part_cnt_t pcnt;54 /** Filesystem type */55 vol_fstype_t fstype;56 } vol_part_info_t;57 58 44 extern int vol_create(vol_t **); 59 45 extern void vol_destroy(vol_t *); 60 46 extern int vol_get_parts(vol_t *, service_id_t **, size_t *); 47 extern int vol_part_add(vol_t *, service_id_t); 61 48 extern int vol_part_info(vol_t *, service_id_t, vol_part_info_t *); 62 49 extern int vol_part_empty(vol_t *, service_id_t); -
uspace/lib/fdisk/src/fdisk.c
r4b6635a7 redebb4a1 58 58 }; 59 59 60 static int fdisk_dev_add_parts(fdisk_dev_t *); 61 static void fdisk_dev_remove_parts(fdisk_dev_t *); 60 62 static int fdisk_part_spec_prepare(fdisk_dev_t *, fdisk_part_spec_t *, 61 63 vbd_part_spec_t *); … … 256 258 } 257 259 260 /** Add partition to our inventory. */ 258 261 static int fdisk_part_add(fdisk_dev_t *dev, vbd_part_id_t partid, 259 262 fdisk_part_t **rpart) … … 268 271 return ENOMEM; 269 272 273 printf("vbd_part_get_info(%zu)\n", partid); 270 274 rc = vbd_part_get_info(dev->fdisk->vbd, partid, &pinfo); 271 275 if (rc != EOK) { … … 274 278 } 275 279 280 printf("vol_part_add(%zu)...\n", pinfo.svc_id); 281 /* 282 * Normally vol service discovers the partition asynchronously. 283 * Here we need to make sure the partition is already known to it. 284 */ 285 rc = vol_part_add(dev->fdisk->vol, pinfo.svc_id); 286 printf("vol_part_add->rc = %d\n", rc); 287 if (rc != EOK && rc != EEXIST) { 288 rc = EIO; 289 goto error; 290 } 291 292 printf("vol_part_info(%zu)\n", pinfo.svc_id); 276 293 rc = vol_part_info(dev->fdisk->vol, pinfo.svc_id, &vpinfo); 294 printf("vol_part_info->rc = %d\n", rc); 277 295 if (rc != EOK) { 278 296 rc = EIO; … … 316 334 } 317 335 336 /** Remove partition from our inventory. */ 337 static void fdisk_part_remove(fdisk_part_t *part) 338 { 339 list_remove(&part->lparts); 340 if (link_used(&part->lpri_ba)) 341 list_remove(&part->lpri_ba); 342 if (link_used(&part->lpri_idx)) 343 list_remove(&part->lpri_idx); 344 if (link_used(&part->llog_ba)) 345 list_remove(&part->llog_ba); 346 free(part); 347 } 348 318 349 static void fdisk_pri_part_insert_lists(fdisk_dev_t *dev, fdisk_part_t *part) 319 350 { … … 373 404 } 374 405 375 int fdisk_dev_open(fdisk_t *fdisk, service_id_t sid, fdisk_dev_t **rdev) 376 { 377 vbd_disk_info_t vinfo; 378 fdisk_dev_t *dev = NULL; 406 static int fdisk_dev_add_parts(fdisk_dev_t *dev) 407 { 379 408 service_id_t *psids = NULL; 380 409 size_t nparts, i; 381 410 int rc; 382 383 dev = calloc(1, sizeof(fdisk_dev_t));384 if (dev == NULL)385 return ENOMEM;386 387 dev->fdisk = fdisk;388 dev->sid = sid;389 list_initialize(&dev->parts);390 list_initialize(&dev->pri_idx);391 list_initialize(&dev->pri_ba);392 list_initialize(&dev->log_ba);393 394 rc = vbd_disk_info(fdisk->vbd, sid, &vinfo);395 if (rc != EOK) {396 rc = EIO;397 goto error;398 }399 411 400 412 printf("get label info\n"); … … 408 420 printf("block size: %zu\n", dev->dinfo.block_size); 409 421 printf("get partitions\n"); 410 rc = vbd_label_get_parts( fdisk->vbd,sid, &psids, &nparts);422 rc = vbd_label_get_parts(dev->fdisk->vbd, dev->sid, &psids, &nparts); 411 423 if (rc != EOK) { 412 424 printf("failed\n"); … … 428 440 429 441 free(psids); 442 return EOK; 443 error: 444 fdisk_dev_remove_parts(dev); 445 return rc; 446 } 447 448 static void fdisk_dev_remove_parts(fdisk_dev_t *dev) 449 { 450 fdisk_part_t *part; 451 452 part = fdisk_part_first(dev); 453 while (part != NULL) { 454 fdisk_part_remove(part); 455 part = fdisk_part_first(dev); 456 } 457 } 458 459 int fdisk_dev_open(fdisk_t *fdisk, service_id_t sid, fdisk_dev_t **rdev) 460 { 461 vbd_disk_info_t vinfo; 462 fdisk_dev_t *dev = NULL; 463 service_id_t *psids = NULL; 464 size_t nparts, i; 465 int rc; 466 467 dev = calloc(1, sizeof(fdisk_dev_t)); 468 if (dev == NULL) 469 return ENOMEM; 470 471 dev->fdisk = fdisk; 472 dev->sid = sid; 473 list_initialize(&dev->parts); 474 list_initialize(&dev->pri_idx); 475 list_initialize(&dev->pri_ba); 476 list_initialize(&dev->log_ba); 477 478 rc = vbd_disk_info(fdisk->vbd, sid, &vinfo); 479 if (rc != EOK) { 480 rc = EIO; 481 goto error; 482 } 483 484 printf("get label info\n"); 485 rc = fdisk_update_dev_info(dev); 486 if (rc != EOK) { 487 printf("failed\n"); 488 rc = EIO; 489 goto error; 490 } 491 492 printf("block size: %zu\n", dev->dinfo.block_size); 493 printf("get partitions\n"); 494 rc = vbd_label_get_parts(fdisk->vbd, sid, &psids, &nparts); 495 if (rc != EOK) { 496 printf("failed\n"); 497 rc = EIO; 498 goto error; 499 } 500 printf("OK\n"); 501 502 printf("found %zu partitions.\n", nparts); 503 for (i = 0; i < nparts; i++) { 504 printf("add partition sid=%zu\n", psids[i]); 505 rc = fdisk_part_add(dev, psids[i], NULL); 506 if (rc != EOK) { 507 printf("failed\n"); 508 goto error; 509 } 510 printf("OK\n"); 511 } 512 513 free(psids); 430 514 *rdev = dev; 431 515 return EOK; … … 440 524 return; 441 525 442 /* XXX Clean up partitions */526 fdisk_dev_remove_parts(dev); 443 527 free(dev); 444 528 } … … 504 588 { 505 589 int rc; 590 591 /* Remove dummy partition */ 592 fdisk_dev_remove_parts(dev); 506 593 507 594 rc = vbd_label_create(dev->fdisk->vbd, dev->sid, ltype); … … 533 620 return EIO; 534 621 622 rc = fdisk_dev_add_parts(dev); 623 if (rc != EOK) 624 return rc; 625 535 626 return EOK; 536 627 } … … 617 708 return EIO; 618 709 619 list_remove(&part->lparts); 620 if (link_used(&part->lpri_ba)) 621 list_remove(&part->lpri_ba); 622 if (link_used(&part->lpri_idx)) 623 list_remove(&part->lpri_idx); 624 if (link_used(&part->llog_ba)) 625 list_remove(&part->llog_ba); 626 free(part); 710 fdisk_part_remove(part); 627 711 return EOK; 628 712 } -
uspace/lib/label/src/gpt.c
r4b6635a7 redebb4a1 544 544 } 545 545 546 static bool gpt_can_delete_part(label_t *label) 547 { 548 return list_count(&label->parts) > 0; 549 } 550 546 551 static int gpt_get_info(label_t *label, label_info_t *linfo) 547 552 { … … 551 556 if (gpt_can_create_pri(label)) 552 557 linfo->flags = linfo->flags | lf_can_create_pri; 558 if (gpt_can_delete_part(label)) 559 linfo->flags = linfo->flags | lf_can_delete_part; 553 560 linfo->ablock0 = label->ablock0; 554 561 linfo->anblocks = label->anblocks; -
uspace/lib/label/src/mbr.c
r4b6635a7 redebb4a1 399 399 } 400 400 401 static bool mbr_can_delete_part(label_t *label) 402 { 403 return list_count(&label->parts) > 0; 404 } 405 401 406 static int mbr_get_info(label_t *label, label_info_t *linfo) 402 407 { … … 416 421 if (label->ext_part != NULL) 417 422 linfo->flags |= lf_can_create_log; 423 /* Can delete partition */ 424 if (mbr_can_delete_part(label)) 425 linfo->flags |= lf_can_delete_part; 418 426 419 427 linfo->ablock0 = label->ablock0; -
uspace/srv/bd/vbd/disk.c
r4b6635a7 redebb4a1 907 907 } 908 908 909 log_msg(LOG_DEFAULT, LVL_NOTE, "loc_service_register('%s')", 910 name); 909 911 rc = loc_service_register(name, &psid); 910 912 if (rc != EOK) { -
uspace/srv/volsrv/part.c
r4b6635a7 redebb4a1 47 47 #include "types/part.h" 48 48 49 static int vol_part_add(service_id_t); 50 49 static int vol_part_add_locked(service_id_t); 51 50 static LIST_INITIALIZE(vol_parts); /* of vol_part_t */ 52 51 static FIBRIL_MUTEX_INITIALIZE(vol_parts_lock); … … 91 90 log_msg(LOG_DEFAULT, LVL_NOTE, "Found partition '%lu'", 92 91 (unsigned long) svcs[i]); 93 rc = vol_part_add (svcs[i]);92 rc = vol_part_add_locked(svcs[i]); 94 93 if (rc != EOK) { 95 94 log_msg(LOG_DEFAULT, LVL_ERROR, "Could not add " … … 128 127 } 129 128 130 static int vol_part_add (service_id_t sid)129 static int vol_part_add_locked(service_id_t sid) 131 130 { 132 131 vol_part_t *part; … … 135 134 136 135 assert(fibril_mutex_is_locked(&vol_parts_lock)); 136 137 /* Check for duplicates */ 138 rc = vol_part_find_by_id(sid, &part); 139 if (rc == EOK) 140 return EEXIST; 137 141 138 142 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_add()"); … … 160 164 list_append(&part->lparts, &vol_parts); 161 165 166 log_msg(LOG_DEFAULT, LVL_NOTE, "Added partition %zu", part->svc_id); 167 162 168 return EOK; 163 169 164 170 error: 165 171 vol_part_delete(part); 172 return rc; 173 } 174 175 int vol_part_add(service_id_t sid) 176 { 177 int rc; 178 179 fibril_mutex_lock(&vol_parts_lock); 180 rc = vol_part_add_locked(sid); 181 fibril_mutex_unlock(&vol_parts_lock); 182 166 183 return rc; 167 184 } -
uspace/srv/volsrv/part.h
r4b6635a7 redebb4a1 40 40 #include <loc.h> 41 41 #include <sys/types.h> 42 #include < vol.h>42 #include <types/vol.h> 43 43 #include "types/part.h" 44 44 45 45 extern int vol_part_init(void); 46 46 extern int vol_part_discovery_start(void); 47 extern int vol_part_add(service_id_t); 47 48 extern int vol_part_get_ids(service_id_t *, size_t, size_t *); 48 49 extern int vol_part_find_by_id(service_id_t, vol_part_t **); -
uspace/srv/volsrv/volsrv.c
r4b6635a7 redebb4a1 44 44 #include <stdlib.h> 45 45 #include <task.h> 46 #include < vol.h>46 #include <types/vol.h> 47 47 48 48 #include "part.h" … … 116 116 } 117 117 118 static void vol_part_add_srv(ipc_callid_t iid, ipc_call_t *icall) 119 { 120 service_id_t sid; 121 int rc; 122 123 sid = IPC_GET_ARG1(*icall); 124 125 rc = vol_part_add(sid); 126 if (rc != EOK) { 127 async_answer_0(iid, rc); 128 return; 129 } 130 131 async_answer_0(iid, EOK); 132 } 133 134 118 135 static void vol_part_info_srv(ipc_callid_t iid, ipc_call_t *icall) 119 136 { … … 124 141 125 142 sid = IPC_GET_ARG1(*icall); 143 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_info_srv(%zu)", 144 sid); 126 145 rc = vol_part_find_by_id(sid, &part); 127 146 if (rc != EOK) { 128 147 async_answer_0(iid, ENOENT); 148 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_info_srv(%zu) - " 149 "not found", sid); 129 150 return; 130 151 } … … 133 154 if (rc != EOK) { 134 155 async_answer_0(iid, EIO); 156 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_info_srv(%zu) - " 157 "get info failed (%d)", sid, rc); 135 158 return; 136 159 } … … 141 164 async_answer_0(callid, EREFUSED); 142 165 async_answer_0(iid, EREFUSED); 166 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_info_srv(%zu) - " 167 "read receive failed", sid); 143 168 return; 144 169 } … … 147 172 async_answer_0(callid, EINVAL); 148 173 async_answer_0(iid, EINVAL); 174 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_info_srv(%zu) - " 175 "incorrect size", sid); 149 176 return; 150 177 } … … 155 182 async_answer_0(callid, rc); 156 183 async_answer_0(iid, rc); 157 return; 158 } 159 184 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_info_srv(%zu) - " 185 "data read failed", sid); 186 return; 187 } 188 189 log_msg(LOG_DEFAULT, LVL_NOTE, "vol_part_info_srv(%zu) - " 190 "success", sid); 160 191 async_answer_0(iid, EOK); 161 192 } … … 206 237 vol_get_parts_srv(callid, &call); 207 238 break; 239 case VOL_PART_ADD: 240 vol_part_add_srv(callid, &call); 241 break; 208 242 case VOL_PART_INFO: 209 243 vol_part_info_srv(callid, &call);
Note:
See TracChangeset
for help on using the changeset viewer.