Changeset deacc58d in mainline for uspace/lib/label/src/gpt.c
- Timestamp:
- 2017-06-20T17:34:02Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 80da8f70
- Parents:
- 63e27ef
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note:
See TracChangeset
for help on using the changeset viewer.