Changes in uspace/lib/mbr/libmbr.c [a2aa81cb:9bda5d90] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/mbr/libmbr.c
ra2aa81cb r9bda5d90 46 46 47 47 static br_block_t * alloc_br(void); 48 static int decode_part(pt_entry_t *, mbr_part_t *, uint32_t); 49 static int decode_logical(mbr_label_t *, mbr_part_t *); 50 static void encode_part(mbr_part_t *, pt_entry_t *, uint32_t, bool); 51 static int check_overlap(mbr_part_t *, mbr_part_t *); 52 static int check_encaps(mbr_part_t *, mbr_part_t *); 53 static int check_preceeds(mbr_part_t *, mbr_part_t *); 54 55 /** Allocate and initialize mbr_label_t structure */ 56 mbr_label_t * mbr_alloc_label(void) 57 { 58 mbr_label_t *label = malloc(sizeof(mbr_label_t)); 59 if (label == NULL) 60 return NULL; 61 62 label->mbr = NULL; 63 label->parts = NULL; 64 label->device = 0; 65 66 return label; 67 } 68 69 /** Free mbr_label_t structure */ 70 void mbr_free_label(mbr_label_t *label) 71 { 72 if (label->mbr != NULL) 73 mbr_free_mbr(label->mbr); 74 75 if (label->parts != NULL) 76 mbr_free_partitions(label->parts); 77 78 free(label); 79 } 48 static int decode_part(pt_entry_t * src, mbr_part_t * trgt, uint32_t base); 49 static int decode_logical(mbr_t * mbr, mbr_partitions_t * p, mbr_part_t * ext); 50 static void encode_part(mbr_part_t * src, pt_entry_t * trgt, uint32_t base, bool ebr); 51 static int check_overlap(mbr_part_t * p1, mbr_part_t * p2); 52 static int check_encaps(mbr_part_t * inner, mbr_part_t * outer); 53 static int check_preceeds(mbr_part_t * preceeder, mbr_part_t * precedee); 80 54 81 55 /** Allocate memory for mbr_t */ … … 86 60 87 61 /** Read MBR from specific device 88 * @param label label to write data to 89 * @param dev_handle device to read MBR from 90 * 91 * @return EOK on success, error code on error 92 */ 93 int mbr_read_mbr(mbr_label_t *label, service_id_t dev_handle) 94 { 95 if (label == NULL) 96 return EINVAL; 97 62 * @param dev_handle device to read MBR from 63 * 64 * @return mbr record on success, NULL on error 65 */ 66 mbr_t * mbr_read_mbr(service_id_t dev_handle) 67 { 98 68 int rc; 99 100 if (label->mbr == NULL) { 101 label->mbr = mbr_alloc_mbr(); 102 if (label->mbr == NULL) { 103 return ENOMEM; 104 } 69 70 mbr_t * mbr = malloc(sizeof(mbr_t)); 71 if (mbr == NULL) { 72 return NULL; 105 73 } 106 74 107 75 rc = block_init(EXCHANGE_ATOMIC, dev_handle, 512); 108 if (rc != EOK) 109 return rc; 110 111 rc = block_read_direct(dev_handle, 0, 1, &(label->mbr->raw_data)); 76 if (rc != EOK) { 77 free(mbr); 78 return NULL; 79 } 80 81 rc = block_read_direct(dev_handle, 0, 1, &(mbr->raw_data)); 82 if (rc != EOK) { 83 free(mbr); 84 block_fini(dev_handle); 85 return NULL; 86 } 87 112 88 block_fini(dev_handle); 113 if (rc != EOK) 114 return rc; 115 116 label->device = dev_handle; 117 118 return EOK; 89 90 mbr->device = dev_handle; 91 92 return mbr; 119 93 } 120 94 121 95 /** Write mbr to disk 122 * @param labelMBR to be written96 * @param mbr MBR to be written 123 97 * @param dev_handle device handle to write MBR to (may be different 124 98 * from the device in 'mbr') … … 126 100 * @return 0 on success, otherwise libblock error code 127 101 */ 128 int mbr_write_mbr(mbr_ label_t *label, service_id_t dev_handle)102 int mbr_write_mbr(mbr_t * mbr, service_id_t dev_handle) 129 103 { 130 104 int rc; … … 135 109 } 136 110 137 rc = block_write_direct(dev_handle, 0, 1, &( label->mbr->raw_data));111 rc = block_write_direct(dev_handle, 0, 1, &(mbr->raw_data)); 138 112 block_fini(dev_handle); 139 113 if (rc != EOK) { … … 141 115 } 142 116 143 return EOK;117 return 0; 144 118 } 145 119 … … 150 124 * @return 1 if MBR, 0 if GPT 151 125 */ 152 int mbr_is_mbr(mbr_label_t *label) 153 { 154 return (label->mbr->raw_data.pte[0].ptype != PT_GPT) ? 1 : 0; 155 } 156 157 /** Parse partitions from MBR, freeing previous partitions if any 158 * NOTE: it is assumed mbr_read_mbr(label) was called before. 159 * @param label MBR to be parsed 160 * 161 * @return linked list of partitions or NULL on error 162 */ 163 int mbr_read_partitions(mbr_label_t *label) 164 { 165 if (label == NULL || label->mbr == NULL) 166 return EINVAL; 167 168 int rc, rc_ext; 169 unsigned int i; 170 mbr_part_t *p; 171 mbr_part_t *ext = NULL; 172 //mbr_partitions_t *parts; 173 printf("check\n"); 174 if (label->parts != NULL) 175 mbr_free_partitions(label->parts); 176 printf("check2\n"); 177 label->parts = mbr_alloc_partitions(); 178 if (label->parts == NULL) { 179 return ENOMEM; 180 } 181 printf("primary\n"); 182 /* Generate the primary partitions */ 126 int mbr_is_mbr(mbr_t * mbr) 127 { 128 return (mbr->raw_data.pte[0].ptype != PT_GPT) ? 1 : 0; 129 } 130 131 /** Parse partitions from MBR 132 * @param mbr MBR to be parsed 133 * 134 * @return linked list of partitions or NULL on error 135 */ 136 mbr_partitions_t * mbr_read_partitions(mbr_t * mbr) 137 { 138 int rc, i, rc_ext; 139 mbr_part_t * p; 140 mbr_part_t * ext = NULL; 141 mbr_partitions_t * parts; 142 143 if (mbr == NULL) 144 return NULL; 145 146 parts = mbr_alloc_partitions(); 147 if (parts == NULL) { 148 return NULL; 149 } 150 151 // Generate the primary partitions 183 152 for (i = 0; i < N_PRIMARY; ++i) { 184 if ( label->mbr->raw_data.pte[i].ptype == PT_UNUSED)153 if (mbr->raw_data.pte[i].ptype == PT_UNUSED) 185 154 continue; 186 printf("pcheck1\n");155 187 156 p = mbr_alloc_partition(); 188 157 if (p == NULL) { 189 158 printf(LIBMBR_NAME ": Error on memory allocation.\n"); 190 mbr_free_partitions( label->parts);191 return ENOMEM;192 } 193 printf("pcheck2\n");194 rc_ext = decode_part(&( label->mbr->raw_data.pte[i]), p, 0);159 mbr_free_partitions(parts); 160 return NULL; 161 } 162 163 rc_ext = decode_part(&(mbr->raw_data.pte[i]), p, 0); 195 164 mbr_set_flag(p, ST_LOGIC, false); 196 rc = mbr_add_partition( label, p);165 rc = mbr_add_partition(parts, p); 197 166 if (rc != ERR_OK) { 198 167 printf(LIBMBR_NAME ": Error occured during decoding the MBR. (%d)\n" \ 199 LIBMBR_NAME ": MBR is invalid.\n", rc); 200 mbr_free_partitions(label->parts); 201 return EINVAL; 202 } 203 printf("pcheck3\n"); 168 LIBMBR_NAME ": Partition list may be incomplete.\n", rc); 169 return NULL; 170 } 171 204 172 if (rc_ext) { 205 173 ext = p; 206 label->parts->l_extended = list_nth(&(label->parts->list), i); 207 } 208 printf("pcheck4\n"); 209 } 210 printf("logical\n"); 211 /* Fill in the primary partitions and generate logical ones, if any */ 212 rc = decode_logical(label, ext); 174 parts->l_extended = list_last(&(parts->list)); 175 } 176 } 177 178 // Fill in the primary partitions and generate logical ones, if any 179 rc = decode_logical(mbr, parts, ext); 213 180 if (rc != EOK) { 214 181 printf(LIBMBR_NAME ": Error occured during decoding the MBR.\n" \ 215 182 LIBMBR_NAME ": Partition list may be incomplete.\n"); 216 return rc; 217 } 218 printf("finish\n"); 219 return EOK; 183 } 184 185 return parts; 220 186 } 221 187 222 188 /** Write MBR and partitions to device 223 * @param label label to write 224 * @param dev_handle device to write the data to 225 * 226 * @return returns EOK on succes, specific error code otherwise 227 */ 228 int mbr_write_partitions(mbr_label_t *label, service_id_t dev_handle) 189 * @param parts partition list to be written 190 * @param mbr MBR to be written with 'parts' partitions 191 * @param dev_handle device to write the data to 192 * 193 * @return returns EOK on succes, specific error code otherwise 194 */ 195 int mbr_write_partitions(mbr_partitions_t * parts, mbr_t * mbr, service_id_t dev_handle) 229 196 { 230 197 int i = 0; 231 198 int rc; 232 mbr_part_t * p;233 mbr_part_t * ext = (label->parts->l_extended == NULL) ? NULL234 : list_get_instance( label->parts->l_extended, mbr_part_t, link);199 mbr_part_t * p; 200 mbr_part_t * ext = (parts->l_extended == NULL) ? NULL 201 : list_get_instance(parts->l_extended, mbr_part_t, link); 235 202 236 203 rc = block_init(EXCHANGE_ATOMIC, dev_handle, 512); … … 240 207 } 241 208 242 link_t * l = label->parts->list.head.next;243 244 / * Encoding primary partitions */245 for (i = 0; i < label->parts->n_primary; i++) {246 p = list_get_instance(l, mbr_part_t, link); 247 encode_part(p, &( label->mbr->raw_data.pte[i]), 0, false);209 link_t * l = parts->list.head.next; 210 211 // Encoding primary partitions 212 for (i = 0; i < parts->n_primary; i++) { 213 p = list_get_instance(l, mbr_part_t, link); 214 encode_part(p, &(mbr->raw_data.pte[i]), 0, false); 248 215 l = l->next; 249 216 } 250 217 251 / * Writing MBR */252 rc = block_write_direct(dev_handle, 0, 1, &( label->mbr->raw_data));218 // Writing MBR 219 rc = block_write_direct(dev_handle, 0, 1, &(mbr->raw_data)); 253 220 if (rc != EOK) { 254 221 printf(LIBMBR_NAME ": Error while writing MBR : %d - %s.\n", rc, str_error(rc)); … … 267 234 * as much power over it as you can get. Thanks. */ 268 235 269 / * Encoding and writing first logical partition */270 if (l != &( label->parts->list.head)) {236 // Encoding and writing first logical partition 237 if (l != &(parts->list.head)) { 271 238 p = list_get_instance(l, mbr_part_t, link); 272 239 p->ebr_addr = base; … … 289 256 prev_p = p; 290 257 291 / * Encoding and writing logical partitions */292 while (l != &( label->parts->list.head)) {258 // Encoding and writing logical partitions 259 while (l != &(parts->list.head)) { 293 260 p = list_get_instance(l, mbr_part_t, link); 294 261 … … 319 286 } 320 287 321 / * write the last EBR */288 // write the last EBR 322 289 encode_part(NULL, &(prev_p->ebr->pte[1]), 0, false); 323 290 rc = block_write_direct(dev_handle, prev_p->ebr_addr, 1, prev_p->ebr); … … 338 305 mbr_part_t * mbr_alloc_partition(void) 339 306 { 340 mbr_part_t * p = malloc(sizeof(mbr_part_t));307 mbr_part_t * p = malloc(sizeof(mbr_part_t)); 341 308 if (p == NULL) { 342 309 return NULL; … … 345 312 link_initialize(&(p->link)); 346 313 p->ebr = NULL; 347 p->type = PT_UNUSED;314 p->type = 0; 348 315 p->status = 0; 349 316 p->start_addr = 0; 350 317 p->length = 0; 351 318 p->ebr_addr = 0; 352 319 353 320 return p; 354 321 } … … 357 324 mbr_partitions_t * mbr_alloc_partitions(void) 358 325 { 359 mbr_partitions_t * parts = malloc(sizeof(mbr_partitions_t));326 mbr_partitions_t * parts = malloc(sizeof(mbr_partitions_t)); 360 327 if (parts == NULL) { 361 328 return NULL; 362 329 } 363 330 364 331 list_initialize(&(parts->list)); 365 332 parts->n_primary = 0; 366 333 parts->n_logical = 0; 367 334 parts->l_extended = NULL; 368 369 /* add blank primary partitions */370 int i;371 mbr_part_t *p;372 for (i = 0; i < N_PRIMARY; ++i) {373 p = mbr_alloc_partition();374 if (p == NULL) {375 mbr_free_partitions(parts);376 return NULL;377 }378 list_append(&(p->link), &(parts->list));379 }380 381 335 382 336 return parts; … … 386 340 * Performs checks, sorts the list. 387 341 * 388 * @param label labelto add to342 * @param parts partition list to add to 389 343 * @param p partition to add 390 344 * 391 345 * @return ERR_OK (0) on success, other MBR_ERR_VAL otherwise 392 346 */ 393 mbr_err_val mbr_add_partition(mbr_label_t *label, mbr_part_t *p) 394 { 395 int rc; 396 mbr_partitions_t *parts = label->parts; 397 398 aoff64_t nblocks; 399 printf("add1.\n"); 400 rc = block_init(EXCHANGE_ATOMIC, label->device, 512); 401 if (rc != EOK) { 402 printf(LIBMBR_NAME ": Error while getting number of blocks: %d - %s.\n", rc, str_error(rc)); 403 return ERR_LIBBLOCK; 404 } 405 printf("add2.\n"); 406 rc = block_get_nblocks(label->device, &nblocks); 407 block_fini(label->device); 408 if (rc != EOK) { 409 printf(LIBMBR_NAME ": Error while getting number of blocks: %d - %s.\n", rc, str_error(rc)); 410 return ERR_LIBBLOCK; 411 } 412 printf("add3.\n"); 413 if (mbr_get_flag(p, ST_LOGIC)) { 414 /* adding logical partition */ 415 416 /* is there any extended partition? */ 347 MBR_ERR_VAL mbr_add_partition(mbr_partitions_t * parts, mbr_part_t * p) 348 { 349 if (mbr_get_flag(p, ST_LOGIC)) { // adding logical part 350 // is there any extended partition? 417 351 if (parts->l_extended == NULL) 418 352 return ERR_NO_EXTENDED; 419 353 420 / * is the logical partition inside the extended one? */421 mbr_part_t * ext = list_get_instance(parts->l_extended, mbr_part_t, link);354 // is the logical partition inside the extended one? 355 mbr_part_t * ext = list_get_instance(parts->l_extended, mbr_part_t, link); 422 356 if (!check_encaps(p, ext)) 423 357 return ERR_OUT_BOUNDS; 424 358 425 / * find a place for the new partition in a sorted linked list */426 //mbr_part_t *last = list_get_instance(list_last(&(parts->list)), mbr_part_t, link);427 mbr_part_t * iter;428 //uint32_t ebr_space = 1;359 // find a place for the new partition in a sorted linked list 360 mbr_part_t * last = list_get_instance(list_last(&(parts->list)), mbr_part_t, link); 361 mbr_part_t * iter; 362 uint32_t ebr_space = 1; 429 363 mbr_part_foreach(parts, iter) { 430 364 if (mbr_get_flag(iter, ST_LOGIC)) { … … 432 366 return ERR_OVERLAP; 433 367 if (check_preceeds(iter, p)) { 434 /* checking if there's at least one sector of space preceeding */ 435 if ((iter->start_addr + iter->length) >= p->start_addr - 1) 436 return ERR_NO_EBR; 437 } else { 438 /* checking if there's at least one sector of space following (for following partitions's EBR) */ 439 if ((p->start_addr + p->length) >= iter->start_addr - 1) 440 return ERR_NO_EBR; 441 } 368 last = iter; 369 ebr_space = p->start_addr - (last->start_addr + last->length); 370 } else 371 break; 442 372 } 443 373 } 444 374 445 /* alloc EBR if it's not already there */ 375 // checking if there's at least one sector of space preceeding 376 if (ebr_space < 1) 377 return ERR_NO_EBR; 378 379 // checking if there's at least one sector of space following (for following partitions's EBR) 380 if (last->link.next != &(parts->list.head)) { 381 if (list_get_instance(&(last->link.next), mbr_part_t, link)->start_addr <= p->start_addr + p->length + 1) 382 return ERR_NO_EBR; 383 } 384 385 // alloc EBR if it's not already there 446 386 if (p->ebr == NULL) { 447 387 p->ebr = alloc_br(); … … 451 391 } 452 392 453 / * add it */454 list_ append(&(p->link), &(parts->list));393 // add it 394 list_insert_after(&(p->link), &(last->link)); 455 395 parts->n_logical += 1; 456 } else { 457 /* adding primary */ 458 396 } else { // adding primary 459 397 if (parts->n_primary == 4) { 460 398 return ERR_PRIMARY_FULL; 461 399 } 462 400 463 / * Check if partition makes space for MBR itself. */464 if (p->start_addr == 0 || ((aoff64_t) p->start_addr) + p->length >= nblocks) {401 // TODO: should we check if it's inside the drive's upper boundary? 402 if (p->start_addr == 0) { 465 403 return ERR_OUT_BOUNDS; 466 404 } 467 printf("add4.\n");468 / * if it's extended, is there any other one? */405 406 // if it's extended, is there any other one? 469 407 if ((p->type == PT_EXTENDED || p->type == PT_EXTENDED_LBA) && parts->l_extended != NULL) { 470 408 return ERR_EXTENDED_PRESENT; 471 409 } 472 printf("add5.\n"); 473 /* find a place and add it */ 474 mbr_part_t *iter; 475 mbr_part_t *empty = NULL; 476 mbr_part_foreach(parts, iter) { 477 printf("type: %x\n", iter->type); 478 if (iter->type == PT_UNUSED) { 479 if (empty == NULL) 480 empty = iter; 481 } else if (check_overlap(p, iter)) 482 return ERR_OVERLAP; 483 } 484 printf("add6. %p, %p\n", empty, p); 485 list_insert_after(&(p->link), &(empty->link)); 486 printf("add6.1.\n"); 487 list_remove(&(empty->link)); 488 printf("add6.2.\n"); 489 free(empty); 490 printf("add7.\n"); 410 411 // find a place and add it 412 if (list_empty(&(parts->list))) { 413 list_append(&(p->link), &(parts->list)); 414 } else { 415 mbr_part_t * iter; 416 mbr_part_foreach(parts, iter) { 417 if (mbr_get_flag(iter, ST_LOGIC)) { 418 list_insert_before(&(p->link), &(iter->link)); 419 break; 420 } else if (check_overlap(p, iter)) 421 return ERR_OVERLAP; 422 } 423 if (iter == list_get_instance(&(parts->list.head.prev), mbr_part_t, link)) 424 list_append(&(p->link), &(parts->list)); 425 } 491 426 parts->n_primary += 1; 492 427 … … 494 429 parts->l_extended = &(p->link); 495 430 } 496 printf("add8.\n"); 431 497 432 return ERR_OK; 498 433 } … … 500 435 /** Remove partition 501 436 * Removes partition by index, indexed from zero. When removing extended 502 * 437 * partition, all logical partitions get removed as well. 503 438 * 504 * @param label labelto remove from439 * @param parts partition list to remove from 505 440 * @param idx index of the partition to remove 506 441 * 507 442 * @return EOK on success, EINVAL if idx invalid 508 443 */ 509 int mbr_remove_partition(mbr_ label_t *label, size_t idx)510 { 511 link_t * l = list_nth(&(label->parts->list), idx);444 int mbr_remove_partition(mbr_partitions_t * parts, size_t idx) 445 { 446 link_t * l = list_nth(&(parts->list), idx); 512 447 if (l == NULL) 513 448 return EINVAL; 514 449 515 mbr_part_t *p; 516 517 /* If we're removing an extended partition, remove all logical as well */ 518 if (l == label->parts->l_extended) { 519 label->parts->l_extended = NULL; 520 521 link_t *it = l->next; 522 link_t *next_it; 523 while (it != &(label->parts->list.head)) { 450 mbr_part_t * p; 451 452 /* TODO: if it is extended partition, should we also remove all logical? 453 * If we don't, we break the consistency of the list. If we do, 454 * the user will have to input them all over again. So yes. */ 455 if (l == parts->l_extended) { 456 parts->l_extended = NULL; 457 458 link_t * it = l->next; 459 link_t * next_it; 460 while (it != &(parts->list.head)) { 524 461 next_it = it->next; 525 462 … … 527 464 if (mbr_get_flag(p, ST_LOGIC)) { 528 465 list_remove(it); 529 label->parts->n_logical -= 1;466 parts->n_logical -= 1; 530 467 mbr_free_partition(p); 531 468 } … … 536 473 } 537 474 538 /* Remove the partition itself */ 475 list_remove(l); 476 539 477 p = list_get_instance(l, mbr_part_t, link); 540 if (mbr_get_flag(p, ST_LOGIC)) { 541 label->parts->n_logical -= 1; 542 list_remove(l); 543 mbr_free_partition(p); 544 } else { 545 /* Cannot remove primary - it would break ordering, just zero it */ 546 label->parts->n_primary -= 1; 547 p->type = 0; 548 p->status = 0; 549 p->start_addr = 0; 550 p->length = 0; 551 p->ebr_addr = 0; 552 } 478 if (mbr_get_flag(p, ST_LOGIC)) 479 parts->n_logical -= 1; 480 else 481 parts->n_primary -= 1; 482 483 484 mbr_free_partition(p); 553 485 554 486 return EOK; … … 556 488 557 489 /** mbr_part_t destructor */ 558 void mbr_free_partition(mbr_part_t * p)490 void mbr_free_partition(mbr_part_t * p) 559 491 { 560 492 if (p->ebr != NULL) … … 564 496 565 497 /** Get flag bool value */ 566 int mbr_get_flag(mbr_part_t * p, MBR_FLAGS flag)498 int mbr_get_flag(mbr_part_t * p, MBR_FLAGS flag) 567 499 { 568 500 return (p->status & (1 << flag)) ? 1 : 0; … … 570 502 571 503 /** Set a specifig status flag to a value */ 572 void mbr_set_flag(mbr_part_t * p, MBR_FLAGS flag, bool value)504 void mbr_set_flag(mbr_part_t * p, MBR_FLAGS flag, bool value) 573 505 { 574 506 uint8_t status = p->status; … … 590 522 591 523 /** Just a wrapper for free() */ 592 void mbr_free_mbr(mbr_t * mbr)524 void mbr_free_mbr(mbr_t * mbr) 593 525 { 594 526 free(mbr); … … 599 531 * @param parts partition list to be freed 600 532 */ 601 void mbr_free_partitions(mbr_partitions_t * parts)533 void mbr_free_partitions(mbr_partitions_t * parts) 602 534 { 603 535 list_foreach_safe(parts->list, cur_link, next) { 604 mbr_part_t *p = list_get_instance(cur_link, mbr_part_t, link); 536 mbr_part_t * p = list_get_instance(cur_link, mbr_part_t, link); 537 list_remove(cur_link); 605 538 mbr_free_partition(p); 606 539 } … … 611 544 // Internal functions follow // 612 545 613 static br_block_t * alloc_br()614 { 615 br_block_t * br = malloc(sizeof(br_block_t));546 static br_block_t * alloc_br() 547 { 548 br_block_t * br = malloc(sizeof(br_block_t)); 616 549 if (br == NULL) 617 550 return NULL; … … 626 559 * @return returns 1, if extended partition, 0 otherwise 627 560 * */ 628 static int decode_part(pt_entry_t * src, mbr_part_t *trgt, uint32_t base)561 static int decode_part(pt_entry_t * src, mbr_part_t * trgt, uint32_t base) 629 562 { 630 563 trgt->type = src->ptype; 631 564 632 565 /* Checking only 0x80; otherwise writing will fix to 0x00 */ 633 trgt->status = (trgt->status & 0xFF00) | src->status; 566 //trgt->bootable = (src->status == B_ACTIVE) ? true : false; 567 mbr_set_flag(trgt, ST_BOOT, (src->status == B_ACTIVE) ? true : false); 634 568 635 569 trgt->start_addr = uint32_t_le2host(src->first_lba) + base; … … 640 574 641 575 /** Parse MBR contents to mbr_part_t list */ 642 static int decode_logical(mbr_ label_t *label, mbr_part_t * ext)576 static int decode_logical(mbr_t * mbr, mbr_partitions_t * parts, mbr_part_t * ext) 643 577 { 644 578 int rc; 645 mbr_part_t *p; 579 mbr_part_t * p; 580 581 if (mbr == NULL || parts == NULL) 582 return EINVAL; 583 646 584 647 585 if (ext == NULL) 648 586 return EOK; 649 587 588 650 589 uint32_t base = ext->start_addr; 651 590 uint32_t addr = base; 652 br_block_t * ebr;653 654 rc = block_init(EXCHANGE_ATOMIC, label->device, 512);591 br_block_t * ebr; 592 593 rc = block_init(EXCHANGE_ATOMIC, mbr->device, 512); 655 594 if (rc != EOK) 656 595 return rc; … … 662 601 } 663 602 664 rc = block_read_direct( label->device, addr, 1, ebr);603 rc = block_read_direct(mbr->device, addr, 1, ebr); 665 604 if (rc != EOK) { 666 605 goto free_ebr_end; … … 687 626 p->ebr = ebr; 688 627 p->ebr_addr = addr; 689 rc = mbr_add_partition( label, p);628 rc = mbr_add_partition(parts, p); 690 629 if (rc != ERR_OK) 691 630 return EINVAL; … … 700 639 } 701 640 702 rc = block_read_direct( label->device, addr, 1, ebr);641 rc = block_read_direct(mbr->device, addr, 1, ebr); 703 642 if (rc != EOK) { 704 643 goto free_ebr_end; … … 721 660 p->ebr = ebr; 722 661 p->ebr_addr = addr; 723 rc = mbr_add_partition( label, p);662 rc = mbr_add_partition(parts, p); 724 663 if (rc != ERR_OK) 725 664 return EINVAL; … … 735 674 736 675 end: 737 block_fini( label->device);676 block_fini(mbr->device); 738 677 739 678 return rc; … … 744 683 { 745 684 if (src != NULL) { 746 //trgt->status = mbr_get_flag(src, ST_BOOT) ? B_ACTIVE : B_INACTIVE; 747 trgt->status = (uint8_t) (src->status & 0xFF); 748 /* ingoring CHS */ 749 trgt->first_chs[0] = 0xFE; 750 trgt->first_chs[1] = 0xFF; 751 trgt->first_chs[2] = 0xFF; 752 trgt->last_chs[0] = 0xFE; 753 trgt->last_chs[1] = 0xFF; 754 trgt->last_chs[2] = 0xFF; 685 trgt->status = mbr_get_flag(src, ST_BOOT) ? B_ACTIVE : B_INACTIVE; 755 686 if (ebr) { // encoding reference to EBR 756 687 trgt->ptype = PT_EXTENDED_LBA;
Note:
See TracChangeset
for help on using the changeset viewer.