Changeset deacc58d in mainline
- Timestamp:
- 2017-06-20T17:34:02Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 80da8f70
- Parents:
- 63e27ef
- Location:
- uspace
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/label/Makefile
r63e27ef rdeacc58d 28 28 29 29 USPACE_PREFIX = ../.. 30 EXTRA_CFLAGS = -Iinclude -I$(LIBBLOCK_PREFIX)30 EXTRA_CFLAGS = -Iinclude 31 31 32 32 LIBRARY = liblabel -
uspace/lib/label/include/label.h
r63e27ef rdeacc58d 37 37 #define LIBLABEL_LABEL_H_ 38 38 39 #include <loc.h>40 39 #include <types/label.h> 41 40 #include <types/liblabel.h> 42 41 43 extern int label_open( service_id_t, label_t **);44 extern int label_create( service_id_t, label_type_t, label_t **);42 extern int label_open(label_bd_t *, label_t **); 43 extern int label_create(label_bd_t *, label_type_t, label_t **); 45 44 extern void label_close(label_t *); 46 45 extern int label_destroy(label_t *); -
uspace/lib/label/include/types/liblabel.h
r63e27ef rdeacc58d 40 40 #include <types/label.h> 41 41 #include <offset.h> 42 #include <stddef.h> 42 43 #include <vol.h> 43 44 #include <uuid.h> … … 48 49 typedef struct label_part_info label_part_info_t; 49 50 typedef struct label_part_spec label_part_spec_t; 51 typedef struct label_bd label_bd_t; 52 typedef struct label_bd_ops label_bd_ops_t; 50 53 51 54 /** Ops for individual label type */ 52 55 typedef struct { 53 int (*open)( service_id_t, label_t **);54 int (*create)( service_id_t, label_t **);56 int (*open)(label_bd_t *, label_t **); 57 int (*create)(label_bd_t *, label_t **); 55 58 void (*close)(label_t *); 56 59 int (*destroy)(label_t *); … … 138 141 } label_mbr_t; 139 142 143 /** Block device operations */ 144 struct label_bd_ops { 145 /** Get block size */ 146 int (*get_bsize)(void *, size_t *); 147 /** Get number of blocks */ 148 int (*get_nblocks)(void *, aoff64_t *); 149 /** Read blocks */ 150 int (*read)(void *, aoff64_t, size_t, void *); 151 /** Write blocks */ 152 int (*write)(void *, aoff64_t, size_t, const void *); 153 }; 154 155 /** Block device */ 156 struct label_bd { 157 /** Ops structure */ 158 label_bd_ops_t *ops; 159 /** Argument */ 160 void *arg; 161 }; 162 140 163 /** Label instance */ 141 164 struct label { … … 144 167 /** Label type */ 145 168 label_type_t ltype; 146 /** Block device service ID*/147 service_id_t svc_id;169 /** Block device */ 170 label_bd_t bd; 148 171 /** Partitions */ 149 172 list_t parts; /* of label_part_t */ -
uspace/lib/label/src/dummy.c
r63e27ef rdeacc58d 34 34 */ 35 35 36 #include <block.h>37 36 #include <errno.h> 38 37 #include <mem.h> … … 41 40 #include "dummy.h" 42 41 43 static int dummy_open( service_id_t, label_t **);44 static int dummy_create( service_id_t, label_t **);42 static int dummy_open(label_bd_t *, label_t **); 43 static int dummy_create(label_bd_t *, label_t **); 45 44 static void dummy_close(label_t *); 46 45 static int dummy_destroy(label_t *); … … 67 66 }; 68 67 69 static int dummy_open( service_id_t sid, label_t **rlabel)68 static int dummy_open(label_bd_t *bd, label_t **rlabel) 70 69 { 71 70 label_t *label = NULL; … … 76 75 int rc; 77 76 78 rc = b lock_get_bsize(sid, &bsize);77 rc = bd->ops->get_bsize(bd->arg, &bsize); 79 78 if (rc != EOK) { 80 79 rc = EIO; … … 82 81 } 83 82 84 rc = b lock_get_nblocks(sid, &nblocks);83 rc = bd->ops->get_nblocks(bd->arg, &nblocks); 85 84 if (rc != EOK) { 86 85 rc = EIO; … … 101 100 label->ops = &dummy_label_ops; 102 101 label->ltype = lt_none; 103 label-> svc_id = sid;102 label->bd = *bd; 104 103 label->ablock0 = ba_min; 105 104 label->anblocks = ba_max - ba_min + 1; … … 129 128 } 130 129 131 static int dummy_create( service_id_t sid, label_t **rlabel)130 static int dummy_create(label_bd_t *bd, label_t **rlabel) 132 131 { 133 132 return ENOTSUP; -
uspace/lib/label/src/gpt.c
r63e27ef rdeacc58d 35 35 36 36 #include <adt/checksum.h> 37 #include <block.h>38 37 #include <byteorder.h> 39 38 #include <errno.h> … … 47 46 #include "gpt.h" 48 47 49 static int gpt_open( service_id_t, label_t **);50 static int gpt_create( service_id_t, label_t **);48 static int gpt_open(label_bd_t *, label_t **); 49 static int gpt_create(label_bd_t *, label_t **); 51 50 static void gpt_close(label_t *); 52 51 static int gpt_destroy(label_t *); … … 71 70 static int gpt_hdr_get_crc(gpt_header_t *, size_t, uint32_t *); 72 71 73 static int gpt_pmbr_create( service_id_t, size_t, uint64_t);74 static int gpt_pmbr_destroy( service_id_t, size_t);72 static int gpt_pmbr_create(label_bd_t *, size_t, uint64_t); 73 static int gpt_pmbr_destroy(label_bd_t *, size_t); 75 74 76 75 const uint8_t efi_signature[8] = { … … 93 92 }; 94 93 95 static int gpt_open( service_id_t sid, label_t **rlabel)94 static int gpt_open(label_bd_t *bd, label_t **rlabel) 96 95 { 97 96 label_t *label = NULL; … … 118 117 etable[1] = NULL; 119 118 120 rc = b lock_get_bsize(sid, &bsize);119 rc = bd->ops->get_bsize(bd->arg, &bsize); 121 120 if (rc != EOK) { 122 121 rc = EIO; … … 141 140 } 142 141 143 rc = b lock_read_direct(sid, gpt_hdr_ba, 1, gpt_hdr[0]);142 rc = bd->ops->read(bd->arg, gpt_hdr_ba, 1, gpt_hdr[0]); 144 143 if (rc != EOK) { 145 144 rc = EIO; … … 149 148 h1ba = uint64_t_le2host(gpt_hdr[0]->alternate_lba); 150 149 151 rc = b lock_read_direct(sid, h1ba, 1, gpt_hdr[1]);150 rc = bd->ops->read(bd->arg, h1ba, 1, gpt_hdr[1]); 152 151 if (rc != EOK) { 153 152 rc = EIO; … … 277 276 } 278 277 279 rc = b lock_read_direct(sid, ptba[j], pt_blocks / 2, etable[j]);278 rc = bd->ops->read(bd->arg, ptba[j], pt_blocks / 2, etable[j]); 280 279 if (rc != EOK) { 281 280 rc = EIO; … … 308 307 label->ops = &gpt_label_ops; 309 308 label->ltype = lt_gpt; 310 label-> svc_id = sid;309 label->bd = *bd; 311 310 label->ablock0 = ba_min; 312 311 label->anblocks = ba_max - ba_min + 1; … … 334 333 } 335 334 336 static int gpt_create( service_id_t sid, label_t **rlabel)335 static int gpt_create(label_bd_t *bd, label_t **rlabel) 337 336 { 338 337 label_t *label = NULL; … … 353 352 int rc; 354 353 355 rc = b lock_get_bsize(sid, &bsize);354 rc = bd->ops->get_bsize(bd->arg, &bsize); 356 355 if (rc != EOK) { 357 356 rc = EIO; … … 364 363 } 365 364 366 rc = b lock_get_nblocks(sid, &nblocks);365 rc = bd->ops->get_nblocks(bd->arg, &nblocks); 367 366 if (rc != EOK) { 368 367 rc = EIO; … … 380 379 } 381 380 382 rc = gpt_pmbr_create( sid, bsize, nblocks);381 rc = gpt_pmbr_create(bd, bsize, nblocks); 383 382 if (rc != EOK) { 384 383 rc = EIO; … … 405 404 } 406 405 407 rc = b lock_write_direct(sid, ptba[i], pt_blocks, etable);406 rc = bd->ops->write(bd->arg, ptba[i], pt_blocks, etable); 408 407 if (rc != EOK) { 409 408 rc = EIO; … … 440 439 gpt_hdr_compute_crc(gpt_hdr, sizeof(gpt_header_t)); 441 440 442 rc = b lock_write_direct(sid, hdr_ba[i], 1, gpt_hdr);441 rc = bd->ops->write(bd->arg, hdr_ba[i], 1, gpt_hdr); 443 442 if (rc != EOK) { 444 443 rc = EIO; … … 460 459 label->ops = &gpt_label_ops; 461 460 label->ltype = lt_gpt; 462 label-> svc_id = sid;461 label->bd = *bd; 463 462 label->ablock0 = ba_min; 464 463 label->anblocks = ba_max - ba_min + 1; … … 520 519 } 521 520 522 rc = block_write_direct(label->svc_id, label->lt.gpt.hdr_ba[i],521 rc = label->bd.ops->write(label->bd.arg, label->lt.gpt.hdr_ba[i], 523 522 1, gpt_hdr); 524 523 if (rc != EOK) { … … 537 536 } 538 537 539 rc = block_write_direct(label->svc_id,538 rc = label->bd.ops->write(label->bd.arg, 540 539 label->lt.gpt.ptable_ba[i], label->lt.gpt.pt_blocks, 541 540 etable); … … 549 548 } 550 549 551 rc = gpt_pmbr_destroy( label->svc_id, label->block_size);550 rc = gpt_pmbr_destroy(&label->bd, label->block_size); 552 551 if (rc != EOK) 553 552 goto error; … … 871 870 nblocks = label->lt.gpt.pt_blocks; 872 871 873 rc = block_read_direct(label->svc_id, ba, nblocks, buf);872 rc = label->bd.ops->read(label->bd.arg, ba, nblocks, buf); 874 873 if (rc != EOK) { 875 874 rc = EIO; … … 888 887 *e = *pte; 889 888 890 rc = block_write_direct(label->svc_id, ba, nblocks, buf);889 rc = label->bd.ops->write(label->bd.arg, ba, nblocks, buf); 891 890 if (rc != EOK) { 892 891 rc = EIO; … … 923 922 924 923 for (i = 0; i < 2; i++) { 925 rc = block_read_direct(label->svc_id,924 rc = label->bd.ops->read(label->bd.arg, 926 925 label->lt.gpt.hdr_ba[i], 1, gpt_hdr); 927 926 if (rc != EOK) { … … 933 932 gpt_hdr_compute_crc(gpt_hdr, label->lt.gpt.hdr_size); 934 933 935 rc = block_write_direct(label->svc_id,934 rc = label->bd.ops->write(label->bd.arg, 936 935 label->lt.gpt.hdr_ba[i], 1, gpt_hdr); 937 936 if (rc != EOK) { … … 940 939 } 941 940 } 942 941 943 942 rc = EOK; 944 943 945 944 exit: 946 945 free(gpt_hdr); … … 974 973 975 974 /** Create GPT Protective MBR */ 976 static int gpt_pmbr_create( service_id_t sid, size_t bsize, uint64_t nblocks)975 static int gpt_pmbr_create(label_bd_t *bd, size_t bsize, uint64_t nblocks) 977 976 { 978 977 mbr_br_block_t *pmbr = NULL; … … 998 997 pmbr->signature = host2uint16_t_le(mbr_br_signature); 999 998 1000 rc = b lock_write_direct(sid, mbr_ba, 1, pmbr);999 rc = bd->ops->write(bd->arg, mbr_ba, 1, pmbr); 1001 1000 if (rc != EOK) { 1002 1001 rc = EIO; … … 1012 1011 1013 1012 /** Destroy GPT Protective MBR */ 1014 static int gpt_pmbr_destroy( service_id_t sid, size_t bsize)1013 static int gpt_pmbr_destroy(label_bd_t *bd, size_t bsize) 1015 1014 { 1016 1015 mbr_br_block_t *pmbr = NULL; … … 1023 1022 } 1024 1023 1025 rc = b lock_write_direct(sid, mbr_ba, 1, pmbr);1024 rc = bd->ops->write(bd->arg, mbr_ba, 1, pmbr); 1026 1025 if (rc != EOK) { 1027 1026 rc = EIO; -
uspace/lib/label/src/label.c
r63e27ef rdeacc58d 51 51 }; 52 52 53 int label_open( service_id_t sid, label_t **rlabel)53 int label_open(label_bd_t *bd, label_t **rlabel) 54 54 { 55 55 label_ops_t **ops; … … 58 58 ops = &probe_list[0]; 59 59 while (ops[0] != NULL) { 60 rc = ops[0]->open( sid, rlabel);60 rc = ops[0]->open(bd, rlabel); 61 61 if (rc == EOK) 62 62 return EOK; … … 67 67 } 68 68 69 int label_create( service_id_t sid, label_type_t ltype, label_t **rlabel)69 int label_create(label_bd_t *bd, label_type_t ltype, label_t **rlabel) 70 70 { 71 71 label_ops_t *ops = NULL; … … 85 85 return ENOTSUP; 86 86 87 return ops->create( sid, rlabel);87 return ops->create(bd, rlabel); 88 88 } 89 89 -
uspace/lib/label/src/mbr.c
r63e27ef rdeacc58d 34 34 */ 35 35 36 #include <block.h>37 36 #include <byteorder.h> 38 37 #include <errno.h> … … 43 42 #include "mbr.h" 44 43 45 static int mbr_open( service_id_t, label_t **);44 static int mbr_open(label_bd_t *, label_t **); 46 45 static int mbr_open_ext(label_t *); 47 static int mbr_create( service_id_t, label_t **);46 static int mbr_create(label_bd_t *, label_t **); 48 47 static void mbr_close(label_t *); 49 48 static int mbr_destroy(label_t *); … … 86 85 }; 87 86 88 static int mbr_open( service_id_t sid, label_t **rlabel)87 static int mbr_open(label_bd_t *bd, label_t **rlabel) 89 88 { 90 89 label_t *label = NULL; … … 97 96 int rc; 98 97 99 rc = b lock_get_bsize(sid, &bsize);100 if (rc != EOK) { 101 rc = EIO; 102 goto error; 103 } 104 105 rc = b lock_get_nblocks(sid, &nblocks);98 rc = bd->ops->get_bsize(bd->arg, &bsize); 99 if (rc != EOK) { 100 rc = EIO; 101 goto error; 102 } 103 104 rc = bd->ops->get_nblocks(bd->arg, &nblocks); 106 105 if (rc != EOK) { 107 106 rc = EIO; … … 125 124 } 126 125 127 rc = b lock_read_direct(sid, mbr_ba, 1, mbr);126 rc = bd->ops->read(bd->arg, mbr_ba, 1, mbr); 128 127 if (rc != EOK) { 129 128 rc = EIO; … … 160 159 label->ops = &mbr_label_ops; 161 160 label->ltype = lt_mbr; 162 label-> svc_id = sid;161 label->bd = *bd; 163 162 label->block_size = bsize; 164 163 label->ablock0 = mbr_ablock0; … … 219 218 while (true) { 220 219 /* Read EBR */ 221 rc = block_read_direct(label->svc_id, ebr_b0, 1, ebr);220 rc = label->bd.ops->read(label->bd.arg, ebr_b0, 1, ebr); 222 221 if (rc != EOK) { 223 222 rc = EIO; … … 280 279 } 281 280 282 static int mbr_create( service_id_t sid, label_t **rlabel)281 static int mbr_create(label_bd_t *bd, label_t **rlabel) 283 282 { 284 283 label_t *label = NULL; … … 289 288 int rc; 290 289 291 rc = b lock_get_bsize(sid, &bsize);292 if (rc != EOK) { 293 rc = EIO; 294 goto error; 295 } 296 297 rc = b lock_get_nblocks(sid, &nblocks);290 rc = bd->ops->get_bsize(bd->arg, &bsize); 291 if (rc != EOK) { 292 rc = EIO; 293 goto error; 294 } 295 296 rc = bd->ops->get_nblocks(bd->arg, &nblocks); 298 297 if (rc != EOK) { 299 298 rc = EIO; … … 321 320 mbr->signature = host2uint16_t_le(mbr_br_signature); 322 321 323 rc = b lock_write_direct(sid, mbr_ba, 1, mbr);322 rc = bd->ops->write(bd->arg, mbr_ba, 1, mbr); 324 323 if (rc != EOK) { 325 324 rc = EIO; … … 333 332 label->ltype = lt_mbr; 334 333 label->block_size = bsize; 335 label-> svc_id = sid;334 label->bd = *bd; 336 335 label->ablock0 = mbr_ablock0; 337 336 label->anblocks = nblocks - mbr_ablock0; … … 387 386 } 388 387 389 rc = block_write_direct(label->svc_id, mbr_ba, 1, mbr);388 rc = label->bd.ops->write(label->bd.arg, mbr_ba, 1, mbr); 390 389 if (rc != EOK) { 391 390 rc = EIO; … … 998 997 return ENOMEM; 999 998 1000 rc = block_read_direct(label->svc_id, mbr_ba, 1, br);999 rc = label->bd.ops->read(label->bd.arg, mbr_ba, 1, br); 1001 1000 if (rc != EOK) { 1002 1001 rc = EIO; … … 1006 1005 br->pte[index] = *pte; 1007 1006 1008 rc = block_write_direct(label->svc_id, mbr_ba, 1, br);1007 rc = label->bd.ops->write(label->bd.arg, mbr_ba, 1, br); 1009 1008 if (rc != EOK) { 1010 1009 rc = EIO; … … 1066 1065 br->signature = host2uint16_t_le(mbr_br_signature); 1067 1066 1068 rc = block_write_direct(label->svc_id, ba, 1, br);1067 rc = label->bd.ops->write(label->bd.arg, ba, 1, br); 1069 1068 if (rc != EOK) { 1070 1069 rc = EIO; … … 1091 1090 ba = part->block0 - part->hdr_blocks; 1092 1091 1093 rc = block_write_direct(label->svc_id, ba, 1, br);1092 rc = label->bd.ops->write(label->bd.arg, ba, 1, br); 1094 1093 if (rc != EOK) { 1095 1094 rc = EIO; … … 1118 1117 return ENOMEM; 1119 1118 1120 rc = block_read_direct(label->svc_id, ba, 1, br);1119 rc = label->bd.ops->read(label->bd.arg, ba, 1, br); 1121 1120 if (rc != EOK) { 1122 1121 rc = EIO; … … 1133 1132 mbr_log_part_to_ptes(part, NULL, &br->pte[mbr_ebr_pte_next]); 1134 1133 1135 rc = block_write_direct(label->svc_id, ba, 1, br);1134 rc = label->bd.ops->write(label->bd.arg, ba, 1, br); 1136 1135 if (rc != EOK) { 1137 1136 rc = EIO; -
uspace/srv/bd/vbd/disk.c
r63e27ef rdeacc58d 75 75 static vbd_part_id_t vbds_part_id = 1; 76 76 77 static int vbds_label_get_bsize(void *, size_t *); 78 static int vbds_label_get_nblocks(void *, aoff64_t *); 79 static int vbds_label_read(void *, aoff64_t, size_t, void *); 80 static int vbds_label_write(void *, aoff64_t, size_t, const void *); 81 82 /** Block device operations provided by VBD */ 77 83 static bd_ops_t vbds_bd_ops = { 78 84 .open = vbds_bd_open, … … 83 89 .get_block_size = vbds_bd_get_block_size, 84 90 .get_num_blocks = vbds_bd_get_num_blocks 91 }; 92 93 /** Provide disk access to liblabel */ 94 static label_bd_ops_t vbds_label_bd_ops = { 95 .get_bsize = vbds_label_get_bsize, 96 .get_nblocks = vbds_label_get_nblocks, 97 .read = vbds_label_read, 98 .write = vbds_label_write 85 99 }; 86 100 … … 450 464 { 451 465 label_t *label = NULL; 466 label_bd_t lbd; 452 467 vbds_disk_t *disk = NULL; 453 468 bool block_inited = false; … … 467 482 return ENOMEM; 468 483 484 /* Must be set before calling label_open */ 485 disk->svc_id = sid; 486 469 487 rc = loc_service_get_name(sid, &disk->svc_name); 470 488 if (rc != EOK) { … … 501 519 block_inited = true; 502 520 503 rc = label_open(sid, &label); 521 lbd.ops = &vbds_label_bd_ops; 522 lbd.arg = (void *) disk; 523 524 rc = label_open(&lbd, &label); 504 525 if (rc != EOK) { 505 526 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to open label in disk %s.", … … 509 530 } 510 531 511 disk->svc_id = sid;512 532 disk->label = label; 513 533 disk->block_size = block_size; … … 648 668 { 649 669 label_t *label; 670 label_bd_t lbd; 650 671 label_info_t linfo; 651 672 vbds_disk_t *disk; … … 683 704 log_msg(LOG_DEFAULT, LVL_DEBUG, "vbds_label_create(%zu) - label_create", sid); 684 705 685 rc = label_create(sid, ltype, &label); 706 lbd.ops = &vbds_label_bd_ops; 707 lbd.arg = (void *) disk; 708 709 rc = label_create(&lbd, ltype, &label); 686 710 if (rc != EOK) 687 711 goto error; … … 695 719 log_msg(LOG_DEFAULT, LVL_DEBUG, "vbds_label_create(%zu) - failure", sid); 696 720 if (disk->label == NULL) { 697 rc2 = label_open(sid, &label); 721 lbd.ops = &vbds_label_bd_ops; 722 lbd.arg = (void *) disk; 723 724 rc2 = label_open(&lbd, &label); 698 725 if (rc2 != EOK) { 699 726 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to open label in disk %s.", … … 713 740 vbds_disk_t *disk; 714 741 label_t *label; 742 label_bd_t lbd; 715 743 int rc; 716 744 … … 735 763 disk->label = NULL; 736 764 737 rc = label_open(disk->svc_id, &label); 765 lbd.ops = &vbds_label_bd_ops; 766 lbd.arg = (void *) disk; 767 768 rc = label_open(&lbd, &label); 738 769 if (rc != EOK) { 739 770 log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to open label in disk %s.", … … 1179 1210 } 1180 1211 1212 /** Get block size wrapper for liblabel */ 1213 static int vbds_label_get_bsize(void *arg, size_t *bsize) 1214 { 1215 vbds_disk_t *disk = (vbds_disk_t *)arg; 1216 return block_get_bsize(disk->svc_id, bsize); 1217 } 1218 1219 /** Get number of blocks wrapper for liblabel */ 1220 static int vbds_label_get_nblocks(void *arg, aoff64_t *nblocks) 1221 { 1222 vbds_disk_t *disk = (vbds_disk_t *)arg; 1223 return block_get_nblocks(disk->svc_id, nblocks); 1224 } 1225 1226 /** Read blocks wrapper for liblabel */ 1227 static int vbds_label_read(void *arg, aoff64_t ba, size_t cnt, void *buf) 1228 { 1229 vbds_disk_t *disk = (vbds_disk_t *)arg; 1230 return block_read_direct(disk->svc_id, ba, cnt, buf); 1231 } 1232 1233 /** Write blocks wrapper for liblabel */ 1234 static int vbds_label_write(void *arg, aoff64_t ba, size_t cnt, const void *data) 1235 { 1236 vbds_disk_t *disk = (vbds_disk_t *)arg; 1237 return block_write_direct(disk->svc_id, ba, cnt, data); 1238 } 1239 1181 1240 /** @} 1182 1241 */
Note:
See TracChangeset
for help on using the changeset viewer.