Changeset 271e24a in mainline for uspace/lib/mbr/libmbr.c
- Timestamp:
- 2013-03-24T00:12:25Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 30440ed
- Parents:
- ec50ac4a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/mbr/libmbr.c
rec50ac4a r271e24a 12 12 * notice, this list of conditions and the following disclaimer in the 13 13 * documentation and/or other materials provided with the distribution. 14 * - The nameof the author may not be used to endorse or promote products14 * - The LIBMBR_NAME of the author may not be used to endorse or promote products 15 15 * derived from this software without specific prior written permission. 16 16 * … … 45 45 46 46 static br_block_t * alloc_br(void); 47 static int decode_part(pt_entry_t * src, part_t * trgt, uint32_t base);48 static int decode_logical(mbr_t * mbr, mbr_part s_t * p,part_t * ext);49 static void encode_part( part_t * src, pt_entry_t * trgt, uint32_t base);47 static int decode_part(pt_entry_t * src, mbr_part_t * trgt, uint32_t base); 48 static int decode_logical(mbr_t * mbr, mbr_partitions_t * p, mbr_part_t * ext); 49 static void encode_part(mbr_part_t * src, pt_entry_t * trgt, uint32_t base); 50 50 51 51 /** Read MBR from specific device … … 123 123 * @return linked list of partitions or NULL on error 124 124 */ 125 mbr_part s_t * mbr_read_partitions(mbr_t * mbr)125 mbr_partitions_t * mbr_read_partitions(mbr_t * mbr) 126 126 { 127 127 int rc, i; 128 part_t * p;129 part_t * ext = NULL;130 mbr_part s_t * parts;128 mbr_part_t * p; 129 mbr_part_t * ext = NULL; 130 mbr_partitions_t * parts; 131 131 132 132 if (mbr == NULL) … … 143 143 continue; 144 144 145 p = malloc(sizeof( part_t));145 p = malloc(sizeof(mbr_part_t)); 146 146 if (p == NULL) { 147 printf( NAME ": Error on memory allocation.\n");147 printf(LIBMBR_NAME ": Error on memory allocation.\n"); 148 148 free(p); 149 149 mbr_free_partitions(parts); … … 159 159 rc = decode_logical(mbr, parts, ext); 160 160 if (rc != EOK) { 161 printf( NAME ": Error occured during decoding the MBR.\n" \162 NAME ": Partition list may be incomplete.\n");161 printf(LIBMBR_NAME ": Error occured during decoding the MBR.\n" \ 162 LIBMBR_NAME ": Partition list may be incomplete.\n"); 163 163 } 164 164 … … 173 173 * @return returns EOK on succes, specific error code otherwise 174 174 */ 175 int mbr_write_partitions(mbr_part s_t * parts, mbr_t * mbr, service_id_t dev_handle)175 int mbr_write_partitions(mbr_partitions_t * parts, mbr_t * mbr, service_id_t dev_handle) 176 176 { 177 177 bool logical = false; 178 178 int i = 0; 179 179 int rc; 180 part_t * p;181 part_t * ext = (parts->l_extended == NULL) ? NULL182 : list_get_instance(parts->l_extended, part_t, link);180 mbr_part_t * p; 181 mbr_part_t * ext = (parts->l_extended == NULL) ? NULL 182 : list_get_instance(parts->l_extended, mbr_part_t, link); 183 183 184 184 br_block_t * last_ebr = NULL; … … 194 194 195 195 aoff64_t addr = ext->start_addr; 196 part_t * prev_part = NULL;196 mbr_part_t * prev_part = NULL; 197 197 198 198 list_foreach(parts->list, it) { 199 p = list_get_instance(it, part_t, link);199 p = list_get_instance(it, mbr_part_t, link); 200 200 if (mbr_get_flag(p, ST_LOGIC)) { 201 201 // writing logical partition … … 269 269 270 270 list_foreach(parts->list, it) { 271 p = list_get_instance(it, part_t, link);271 p = list_get_instance(it, mbr_part_t, link); 272 272 if (mbr_get_flag(p, ST_LOGIC)) { 273 273 // extended does not exist, fail … … 295 295 ext = p; 296 296 297 //p = list_get_instance(p->link.next, mbr_part s_t, link);297 //p = list_get_instance(p->link.next, mbr_partitions_t, link); 298 298 p = p->next; 299 299 } … … 357 357 } 358 358 359 /** part_t constructor */360 part_t * mbr_alloc_partition(void)361 { 362 part_t * p = malloc(sizeof(part_t));359 /** mbr_part_t constructor */ 360 mbr_part_t * mbr_alloc_partition(void) 361 { 362 mbr_part_t * p = malloc(sizeof(mbr_part_t)); 363 363 if (p == NULL) { 364 364 return NULL; … … 374 374 } 375 375 376 mbr_part s_t * mbr_alloc_partitions(void)377 { 378 mbr_part s_t * parts = malloc(sizeof(mbr_parts_t));376 mbr_partitions_t * mbr_alloc_partitions(void) 377 { 378 mbr_partitions_t * parts = malloc(sizeof(mbr_partitions_t)); 379 379 if (parts == NULL) { 380 380 return NULL; … … 387 387 388 388 /** Add partition */ 389 void mbr_add_partition(mbr_parts_t * parts,part_t * partition)389 int mbr_add_partition(mbr_partitions_t * parts, mbr_part_t * partition) 390 390 { 391 391 list_append(&(partition->link), &(parts->list)); 392 return EOK; 392 393 } 393 394 394 395 /** Remove partition */ 395 void mbr_remove_partition(mbr_parts_t * parts, int idx)396 int mbr_remove_partition(mbr_partitions_t * parts, size_t idx) 396 397 { 397 398 link_t * l = list_nth(&(parts->list), idx); 398 399 list_remove(l); 399 part_t * p = list_get_instance(l,part_t, link);400 mbr_part_t * p = list_get_instance(l, mbr_part_t, link); 400 401 mbr_free_partition(p); 401 } 402 403 /** part_t destructor */ 404 void mbr_free_partition(part_t * p) 402 403 return EOK; 404 } 405 406 /** mbr_part_t destructor */ 407 void mbr_free_partition(mbr_part_t * p) 405 408 { 406 409 if (p->ebr != NULL) … … 410 413 411 414 /** Get flag bool value */ 412 int mbr_get_flag( part_t * p, MBR_FLAGS flag)415 int mbr_get_flag(mbr_part_t * p, MBR_FLAGS flag) 413 416 { 414 417 return (p->status & (1 << flag)) ? 1 : 0; … … 416 419 417 420 /** Set a specifig status flag to a value */ 418 void mbr_set_flag( part_t * p, MBR_FLAGS flag, bool value)421 void mbr_set_flag(mbr_part_t * p, MBR_FLAGS flag, bool value) 419 422 { 420 423 uint8_t status = p->status; … … 438 441 * @param parts partition list to be freed 439 442 */ 440 void mbr_free_partitions(mbr_part s_t * parts)443 void mbr_free_partitions(mbr_partitions_t * parts) 441 444 { 442 445 list_foreach_safe(parts->list, cur_link, next) { 443 part_t * p = list_get_instance(cur_link,part_t, link);446 mbr_part_t * p = list_get_instance(cur_link, mbr_part_t, link); 444 447 list_remove(cur_link); 445 448 mbr_free_partition(p); … … 462 465 } 463 466 464 /** Parse partition entry to part_t */465 static int decode_part(pt_entry_t * src, part_t * trgt, uint32_t base)467 /** Parse partition entry to mbr_part_t */ 468 static int decode_part(pt_entry_t * src, mbr_part_t * trgt, uint32_t base) 466 469 { 467 470 trgt->type = src->ptype; … … 477 480 } 478 481 479 /** Parse MBR contents to part_t list482 /** Parse MBR contents to mbr_part_t list 480 483 * parameter 'p' is allocated for only used primary partitions 481 484 */ 482 static int decode_logical(mbr_t * mbr, mbr_part s_t * parts,part_t * ext)485 static int decode_logical(mbr_t * mbr, mbr_partitions_t * parts, mbr_part_t * ext) 483 486 { 484 487 int rc; 485 part_t * p;488 mbr_part_t * p; 486 489 487 490 if (mbr == NULL || parts == NULL) … … 534 537 } 535 538 536 /** Convert part_t to pt_entry_t */537 static void encode_part( part_t * src, pt_entry_t * trgt, uint32_t base)539 /** Convert mbr_part_t to pt_entry_t */ 540 static void encode_part(mbr_part_t * src, pt_entry_t * trgt, uint32_t base) 538 541 { 539 542 if (src != NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.