Changeset b7a4d06 in mainline for uspace/lib/label/src/mbr.c
- Timestamp:
- 2015-07-18T12:55:12Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c43db5f
- Parents:
- 70815a24
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/label/src/mbr.c
r70815a24 rb7a4d06 122 122 123 123 list_initialize(&label->parts); 124 list_initialize(&label->pri_parts); 125 list_initialize(&label->log_parts); 124 126 125 127 /* Verify boot record signature */ … … 130 132 } 131 133 134 label->ext_part_idx = -1; 132 135 for (entry = 0; entry < mbr_nprimary; entry++) { 133 136 eptr = &mbr->pte[entry]; … … 187 190 188 191 list_initialize(&label->parts); 192 list_initialize(&label->pri_parts); 193 list_initialize(&label->log_parts); 189 194 190 195 mbr->media_id = 0; … … 210 215 label->anblocks = nblocks - mbr_ablock0; 211 216 label->pri_entries = mbr_nprimary; 217 label->ext_part_idx = -1; 212 218 213 219 *rlabel = label; … … 225 231 part = mbr_part_first(label); 226 232 while (part != NULL) { 227 list_remove(&part->llabel); 233 list_remove(&part->lparts); 234 if (link_used(&part->lpri)) 235 list_remove(&part->lpri); 236 if (link_used(&part->llog)) 237 list_remove(&part->llog); 228 238 free(part); 229 239 … … 273 283 linfo->dcnt = dc_label; 274 284 linfo->ltype = lt_mbr; 285 286 /* We support extended partitions */ 287 linfo->flags = lf_ext_supp; 288 289 /** Can create primary if there is a free slot */ 290 if (list_count(&label->pri_parts) < mbr_nprimary) 291 linfo->flags |= lf_can_create_pri; 292 /* Can create extended if there is a free slot and no extended */ 293 if ((linfo->flags & lf_can_create_pri) != 0 && label->ext_part_idx < 0) 294 linfo->flags |= lf_can_create_ext; 295 /* Can create logical if there is an extended partition */ 296 if (label->ext_part_idx >= 0) 297 linfo->flags |= lf_can_create_log; 298 275 299 linfo->ablock0 = label->ablock0; 276 300 linfo->anblocks = label->anblocks; 301 277 302 return EOK; 278 303 } … … 286 311 return NULL; 287 312 288 return list_get_instance(link, label_part_t, l label);313 return list_get_instance(link, label_part_t, lparts); 289 314 } 290 315 … … 293 318 link_t *link; 294 319 295 link = list_next(&part->l label, &part->label->parts);320 link = list_next(&part->lparts, &part->label->parts); 296 321 if (link == NULL) 297 322 return NULL; 298 323 299 return list_get_instance(link, label_part_t, llabel); 300 } 301 324 return list_get_instance(link, label_part_t, lparts); 325 } 326 327 #include <io/log.h> 302 328 static void mbr_part_get_info(label_part_t *part, label_part_info_t *pinfo) 303 329 { … … 305 331 pinfo->block0 = part->block0; 306 332 pinfo->nblocks = part->nblocks; 333 334 log_msg(LOG_DEFAULT, LVL_NOTE, "mbr_part_get_info: index=%d ptype=%d", 335 (int)part->index, (int)part->ptype); 336 if (link_used(&part->llog)) 337 pinfo->pkind = lpk_logical; 338 else if (part->ptype == mbr_pt_extended) 339 pinfo->pkind = lpk_extended; 340 else 341 pinfo->pkind = lpk_primary; 307 342 } 308 343 … … 318 353 return ENOMEM; 319 354 320 /* XXX Verify index, block0, nblocks */321 322 if (pspec->index < 1 || pspec->index > label->pri_entries) {323 rc = EINVAL;324 goto error;325 }326 355 327 356 /* XXX Check if index is used */ … … 331 360 part->block0 = pspec->block0; 332 361 part->nblocks = pspec->nblocks; 333 part->ptype = pspec->ptype; 334 335 rc = mbr_part_to_pte(part, &pte); 336 if (rc != EOK) { 337 rc = EINVAL; 338 goto error; 339 } 340 341 rc = mbr_pte_update(label, &pte, pspec->index - 1); 342 if (rc != EOK) { 343 rc = EIO; 344 goto error; 345 } 346 347 list_append(&part->llabel, &label->parts); 362 363 switch (pspec->pkind) { 364 case lpk_primary: 365 part->ptype = pspec->ptype; 366 break; 367 case lpk_extended: 368 part->ptype = mbr_pt_extended; 369 if (pspec->ptype != 0) { 370 rc = EINVAL; 371 goto error; 372 } 373 if (label->ext_part_idx >= 0) { 374 rc = EEXISTS; 375 goto error; 376 } 377 break; 378 case lpk_logical: 379 part->ptype = pspec->ptype; 380 if (pspec->index != 0) { 381 rc = EINVAL; 382 goto error; 383 } 384 break; 385 } 386 387 if (pspec->pkind != lpk_logical) { 388 /* Primary or extended partition */ 389 /* XXX Verify index, block0, nblocks */ 390 391 if (pspec->index < 1 || pspec->index > label->pri_entries) { 392 rc = EINVAL; 393 goto error; 394 } 395 396 rc = mbr_part_to_pte(part, &pte); 397 if (rc != EOK) { 398 rc = EINVAL; 399 goto error; 400 } 401 402 rc = mbr_pte_update(label, &pte, pspec->index - 1); 403 if (rc != EOK) { 404 rc = EIO; 405 goto error; 406 } 407 408 list_append(&part->lparts, &label->parts); 409 list_append(&part->lpri, &label->pri_parts); 410 411 if (pspec->pkind == lpk_extended) 412 label->ext_part_idx = pspec->index - 1; 413 } else { 414 /* Logical partition */ 415 rc = ENOTSUP; 416 goto error; 417 } 348 418 349 419 *rpart = part; … … 367 437 return EIO; 368 438 369 list_remove(&part->llabel); 439 /* If it was the extended partition, clear ext. part. index */ 440 if (part->index - 1 == part->label->ext_part_idx) 441 part->label->ext_part_idx = -1; 442 443 list_remove(&part->lparts); 444 if (link_used(&part->lpri)) 445 list_remove(&part->lpri); 446 if (link_used(&part->llog)) 447 list_remove(&part->llog); 370 448 free(part); 371 449 return EOK; … … 386 464 return EINVAL; 387 465 466 log_msg(LOG_DEFAULT, LVL_NOTE, "mbr_part_to_pte: a0=%" PRIu64 467 " len=%" PRIu64 " ptype=%d", part->block0, part->nblocks, 468 (int)part->ptype); 388 469 memset(pte, 0, sizeof(mbr_pte_t)); 389 470 pte->ptype = part->ptype; … … 403 484 404 485 /* See UEFI specification 2.0 section 5.2.1 Legacy Master Boot Record */ 405 if (pte->ptype == mbr_pt_unused || pte->ptype == mbr_pt_extended || 406 nblocks == 0) 486 if (pte->ptype == mbr_pt_unused || nblocks == 0) 407 487 return EOK; 408 488 … … 411 491 return ENOMEM; 412 492 493 part->ptype = pte->ptype; 413 494 part->index = index; 414 495 part->block0 = block0; … … 422 503 423 504 part->label = label; 424 list_append(&part->llabel, &label->parts); 505 list_append(&part->lparts, &label->parts); 506 list_append(&part->lpri, &label->pri_parts); 507 508 if (pte->ptype == mbr_pt_extended) 509 label->ext_part_idx = index - 1; 425 510 return EOK; 426 511 }
Note:
See TracChangeset
for help on using the changeset viewer.