Changes in uspace/lib/label/src/gpt.c [6a66923:b33d140] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/label/src/gpt.c
r6a66923 rb33d140 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; … … 100 99 uint8_t *etable[2]; 101 100 size_t bsize; 101 aoff64_t nblocks; 102 102 uint32_t num_entries; 103 103 uint32_t esize; … … 118 118 etable[1] = NULL; 119 119 120 rc = block_get_bsize(sid, &bsize); 120 rc = bd->ops->get_bsize(bd->arg, &bsize); 121 if (rc != EOK) { 122 rc = EIO; 123 goto error; 124 } 125 126 rc = bd->ops->get_nblocks(bd->arg, &nblocks); 121 127 if (rc != EOK) { 122 128 rc = EIO; … … 141 147 } 142 148 143 rc = b lock_read_direct(sid, gpt_hdr_ba, 1, gpt_hdr[0]);149 rc = bd->ops->read(bd->arg, gpt_hdr_ba, 1, gpt_hdr[0]); 144 150 if (rc != EOK) { 145 151 rc = EIO; … … 149 155 h1ba = uint64_t_le2host(gpt_hdr[0]->alternate_lba); 150 156 151 rc = block_read_direct(sid, h1ba, 1, gpt_hdr[1]); 157 if (h1ba >= nblocks) { 158 rc = EINVAL; 159 goto error; 160 } 161 162 rc = bd->ops->read(bd->arg, h1ba, 1, gpt_hdr[1]); 152 163 if (rc != EOK) { 153 164 rc = EIO; … … 277 288 } 278 289 279 rc = b lock_read_direct(sid, ptba[j], pt_blocks / 2, etable[j]);290 rc = bd->ops->read(bd->arg, ptba[j], pt_blocks / 2, etable[j]); 280 291 if (rc != EOK) { 281 292 rc = EIO; … … 308 319 label->ops = &gpt_label_ops; 309 320 label->ltype = lt_gpt; 310 label-> svc_id = sid;321 label->bd = *bd; 311 322 label->ablock0 = ba_min; 312 323 label->anblocks = ba_max - ba_min + 1; … … 334 345 } 335 346 336 static int gpt_create( service_id_t sid, label_t **rlabel)347 static int gpt_create(label_bd_t *bd, label_t **rlabel) 337 348 { 338 349 label_t *label = NULL; … … 353 364 int rc; 354 365 355 rc = b lock_get_bsize(sid, &bsize);366 rc = bd->ops->get_bsize(bd->arg, &bsize); 356 367 if (rc != EOK) { 357 368 rc = EIO; … … 364 375 } 365 376 366 rc = b lock_get_nblocks(sid, &nblocks);377 rc = bd->ops->get_nblocks(bd->arg, &nblocks); 367 378 if (rc != EOK) { 368 379 rc = EIO; … … 380 391 } 381 392 382 rc = gpt_pmbr_create( sid, bsize, nblocks);393 rc = gpt_pmbr_create(bd, bsize, nblocks); 383 394 if (rc != EOK) { 384 395 rc = EIO; … … 405 416 } 406 417 407 rc = b lock_write_direct(sid, ptba[i], pt_blocks, etable);418 rc = bd->ops->write(bd->arg, ptba[i], pt_blocks, etable); 408 419 if (rc != EOK) { 409 420 rc = EIO; … … 440 451 gpt_hdr_compute_crc(gpt_hdr, sizeof(gpt_header_t)); 441 452 442 rc = b lock_write_direct(sid, hdr_ba[i], 1, gpt_hdr);453 rc = bd->ops->write(bd->arg, hdr_ba[i], 1, gpt_hdr); 443 454 if (rc != EOK) { 444 455 rc = EIO; … … 460 471 label->ops = &gpt_label_ops; 461 472 label->ltype = lt_gpt; 462 label-> svc_id = sid;473 label->bd = *bd; 463 474 label->ablock0 = ba_min; 464 475 label->anblocks = ba_max - ba_min + 1; … … 520 531 } 521 532 522 rc = block_write_direct(label->svc_id, label->lt.gpt.hdr_ba[i],533 rc = label->bd.ops->write(label->bd.arg, label->lt.gpt.hdr_ba[i], 523 534 1, gpt_hdr); 524 535 if (rc != EOK) { … … 537 548 } 538 549 539 rc = block_write_direct(label->svc_id,550 rc = label->bd.ops->write(label->bd.arg, 540 551 label->lt.gpt.ptable_ba[i], label->lt.gpt.pt_blocks, 541 552 etable); … … 549 560 } 550 561 551 rc = gpt_pmbr_destroy( label->svc_id, label->block_size);562 rc = gpt_pmbr_destroy(&label->bd, label->block_size); 552 563 if (rc != EOK) 553 564 goto error; … … 871 882 nblocks = label->lt.gpt.pt_blocks; 872 883 873 rc = block_read_direct(label->svc_id, ba, nblocks, buf);884 rc = label->bd.ops->read(label->bd.arg, ba, nblocks, buf); 874 885 if (rc != EOK) { 875 886 rc = EIO; … … 888 899 *e = *pte; 889 900 890 rc = block_write_direct(label->svc_id, ba, nblocks, buf);901 rc = label->bd.ops->write(label->bd.arg, ba, nblocks, buf); 891 902 if (rc != EOK) { 892 903 rc = EIO; … … 923 934 924 935 for (i = 0; i < 2; i++) { 925 rc = block_read_direct(label->svc_id,936 rc = label->bd.ops->read(label->bd.arg, 926 937 label->lt.gpt.hdr_ba[i], 1, gpt_hdr); 927 938 if (rc != EOK) { … … 933 944 gpt_hdr_compute_crc(gpt_hdr, label->lt.gpt.hdr_size); 934 945 935 rc = block_write_direct(label->svc_id,946 rc = label->bd.ops->write(label->bd.arg, 936 947 label->lt.gpt.hdr_ba[i], 1, gpt_hdr); 937 948 if (rc != EOK) { … … 940 951 } 941 952 } 942 953 943 954 rc = EOK; 944 955 945 956 exit: 946 957 free(gpt_hdr); … … 974 985 975 986 /** Create GPT Protective MBR */ 976 static int gpt_pmbr_create( service_id_t sid, size_t bsize, uint64_t nblocks)987 static int gpt_pmbr_create(label_bd_t *bd, size_t bsize, uint64_t nblocks) 977 988 { 978 989 mbr_br_block_t *pmbr = NULL; … … 998 1009 pmbr->signature = host2uint16_t_le(mbr_br_signature); 999 1010 1000 rc = b lock_write_direct(sid, mbr_ba, 1, pmbr);1011 rc = bd->ops->write(bd->arg, mbr_ba, 1, pmbr); 1001 1012 if (rc != EOK) { 1002 1013 rc = EIO; … … 1012 1023 1013 1024 /** Destroy GPT Protective MBR */ 1014 static int gpt_pmbr_destroy( service_id_t sid, size_t bsize)1025 static int gpt_pmbr_destroy(label_bd_t *bd, size_t bsize) 1015 1026 { 1016 1027 mbr_br_block_t *pmbr = NULL; … … 1023 1034 } 1024 1035 1025 rc = b lock_write_direct(sid, mbr_ba, 1, pmbr);1036 rc = bd->ops->write(bd->arg, mbr_ba, 1, pmbr); 1026 1037 if (rc != EOK) { 1027 1038 rc = EIO;
Note:
See TracChangeset
for help on using the changeset viewer.