Changeset 2b55edb in mainline
- Timestamp:
- 2013-07-30T08:00:44Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 493b881
- Parents:
- e3bc355
- Location:
- uspace
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified uspace/app/hdisk/func_gpt.c ¶
re3bc355 r2b55edb 184 184 sa = gpt_get_next_aligned(sa, alignment); 185 185 186 printf("Set end addres (number): ");186 printf("Set end address (number): "); 187 187 ea = get_input_uint64(in); 188 188 -
TabularUnified uspace/lib/gpt/libgpt.c ¶
re3bc355 r2b55edb 58 58 static uint8_t get_byte(const char *); 59 59 static bool check_overlap(gpt_part_t *, gpt_part_t *); 60 static bool check_encaps(gpt_part_t *, uint64_t, uint64_t); 60 61 61 62 /** Allocate memory for gpt label */ … … 308 309 goto fini_fail; 309 310 } 310 311 /* 312 * FIXME: so far my boasting about variable partition entry size 313 * will not work. The CRC32 checksums will be different. 314 * This can't be fixed easily - we'd have to run the checksum 315 * on all of the partition entry array. 316 */ 311 317 312 uint32_t crc = compute_crc32((uint8_t *) label->parts->part_array, 318 fillries * sizeof(gpt_entry_t));313 fillries * ent_size); 319 314 320 315 if(uint32_t_le2host(label->gpt->header->pe_array_crc32) != crc) … … 350 345 size_t fillries = label->parts->fill > GPT_MIN_PART_NUM ? label->parts->fill : GPT_MIN_PART_NUM; 351 346 352 label->gpt->header->fillries = host2uint32_t_le(fillries); 353 label->gpt->header->pe_array_crc32 = host2uint32_t_le(compute_crc32( 354 (uint8_t *) label->parts->part_array, 355 fillries * e_size)); 347 if (e_size != sizeof(gpt_entry_t)) 348 return ENOTSUP; 356 349 357 350 /* comm_size of 4096 is ignored */ … … 369 362 goto fail; 370 363 364 label->gpt->header->fillries = host2uint32_t_le(fillries); 371 365 uint64_t arr_blocks = (fillries * sizeof(gpt_entry_t)) / b_size; 372 366 label->gpt->header->first_usable_lba = host2uint64_t_le(arr_blocks + 1); 373 label->gpt->header->last_usable_lba = host2uint64_t_le(n_blocks - arr_blocks - 2); 367 uint64_t first_lba = n_blocks - arr_blocks - 2; 368 label->gpt->header->last_usable_lba = host2uint64_t_le(first_lba); 369 370 /* Perform checks */ 371 gpt_part_foreach(label, p) { 372 if (gpt_get_part_type(p) == GPT_PTE_UNUSED) 373 continue; 374 375 if (!check_encaps(p, n_blocks, first_lba)) { 376 rc = ERANGE; 377 goto fail; 378 } 379 380 gpt_part_foreach(label, q) { 381 if (p == q) 382 continue; 383 384 if (gpt_get_part_type(p) != GPT_PTE_UNUSED) { 385 if (check_overlap(p, q)) { 386 rc = ERANGE; 387 goto fail; 388 } 389 } 390 } 391 } 392 393 label->gpt->header->pe_array_crc32 = host2uint32_t_le(compute_crc32( 394 (uint8_t *) label->parts->part_array, 395 fillries * e_size)); 374 396 375 397 … … 483 505 int gpt_add_partition(gpt_label_t *label, gpt_part_t *partition) 484 506 { 485 /* FIXME: Check dimensions! */486 gpt_part_foreach(label, p) {487 if (gpt_get_part_type(p) != GPT_PTE_UNUSED) {488 if (check_overlap(partition, p))489 return EINVAL;490 }491 }492 493 507 gpt_part_t *p; 494 508 /* Find the first empty entry */ … … 833 847 } 834 848 835 849 static bool check_encaps(gpt_part_t *p, uint64_t n_blocks, uint64_t first_lba) 850 { 851 uint64_t start = uint64_t_le2host(p->start_lba); 852 uint64_t end = uint64_t_le2host(p->end_lba); 853 854 if (start >= first_lba && end < n_blocks - first_lba) 855 return true; 856 857 return false; 858 }
Note:
See TracChangeset
for help on using the changeset viewer.