Changeset 88a27f1 in mainline
- Timestamp:
- 2011-05-13T20:14:32Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0182e5cc
- Parents:
- a8c14aa
- Location:
- uspace/srv/fs/fat
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_fat.c
ra8c14aa r88a27f1 285 285 } 286 286 287 /** Get cluster from the first FAT. 287 /** Get cluster from the first FAT. FAT12 version 288 288 * 289 289 * @param bs Buffer holding the boot sector for the file system. … … 295 295 */ 296 296 int 297 fat_get_cluster (fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno,297 fat_get_cluster_fat12(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno, 298 298 fat_cluster_t clst, fat_cluster_t *value) 299 299 { … … 302 302 int rc; 303 303 304 assert(fatno < FATCNT(bs)); 305 306 if (FAT_IS_FAT12(bs)) 307 offset = (clst + clst/2); 308 else 309 offset = (clst * FAT_CLST_SIZE(bs)); 304 offset = (clst + clst/2); 310 305 311 306 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + … … 314 309 return rc; 315 310 316 if (FAT_IS_FAT12(bs)) { 317 /* This cluster access spans a sector boundary. Check only for FAT12 */ 318 if ((offset % BPS(bs) + 1 == BPS(bs))) { 319 /* Is it last sector of FAT? */ 320 if (offset / BPS(bs) < SF(bs)) { 321 /* No. Reading next sector */ 322 rc = block_get(&b1, devmap_handle, 1 + RSCNT(bs) + 323 SF(bs)*fatno + offset / BPS(bs), BLOCK_FLAGS_NONE); 324 if (rc != EOK) { 325 block_put(b); 326 return rc; 327 } 328 /* 329 * Combining value with last byte of current sector and 330 * first byte of next sector 331 */ 332 *value = *(uint8_t *)(b->data + BPS(bs) - 1); 333 *value |= *(uint8_t *)(b1->data) << 8; 334 335 rc = block_put(b1); 336 if (rc != EOK) { 337 block_put(b); 338 return rc; 339 } 311 /* This cluster access spans a sector boundary. Check only for FAT12 */ 312 if ((offset % BPS(bs) + 1 == BPS(bs))) { 313 /* Is it last sector of FAT? */ 314 if (offset / BPS(bs) < SF(bs)) { 315 /* No. Reading next sector */ 316 rc = block_get(&b1, devmap_handle, 1 + RSCNT(bs) + 317 SF(bs)*fatno + offset / BPS(bs), BLOCK_FLAGS_NONE); 318 if (rc != EOK) { 319 block_put(b); 320 return rc; 340 321 } 341 else { 342 /* Yes. It is last sector of FAT */ 322 /* 323 * Combining value with last byte of current sector and 324 * first byte of next sector 325 */ 326 *value = *(uint8_t *)(b->data + BPS(bs) - 1); 327 *value |= *(uint8_t *)(b1->data) << 8; 328 329 rc = block_put(b1); 330 if (rc != EOK) { 343 331 block_put(b); 344 return ERANGE;332 return rc; 345 333 } 346 334 } 347 else 348 *value = *(uint16_t *)(b->data + offset % BPS(bs)); 349 350 if (IS_ODD(clst)) 351 *value = (*value) >> 4; 352 else 353 *value = (*value) & FAT12_MASK; 354 } 355 else { 356 if (FAT_IS_FAT32(bs)) 357 *value = *(uint32_t *)(b->data + offset % BPS(bs)) & FAT32_MASK; 358 else 359 *value = *(uint16_t *)(b->data + offset % BPS(bs)); 360 } 361 362 *value = uint32_t_le2host(*value); 335 else { 336 /* Yes. It is last sector of FAT */ 337 block_put(b); 338 return ERANGE; 339 } 340 } 341 else 342 *value = *(uint16_t *)(b->data + offset % BPS(bs)); 343 344 if (IS_ODD(clst)) 345 *value = (*value) >> 4; 346 else 347 *value = (*value) & FAT12_MASK; 348 349 *value = uint16_t_le2host(*value); 363 350 rc = block_put(b); 364 351 … … 366 353 } 367 354 368 /** Set cluster in one instance of FAT. 355 /** Get cluster from the first FAT. FAT16 version 356 * 357 * @param bs Buffer holding the boot sector for the file system. 358 * @param devmap_handle Device handle for the file system. 359 * @param clst Cluster which to get. 360 * @param value Output argument holding the value of the cluster. 361 * 362 * @return EOK or a negative error code. 363 */ 364 int 365 fat_get_cluster_fat16(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno, 366 fat_cluster_t clst, fat_cluster_t *value) 367 { 368 block_t *b; 369 aoff64_t offset; 370 int rc; 371 372 offset = (clst * FAT16_CLST_SIZE); 373 374 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + 375 offset / BPS(bs), BLOCK_FLAGS_NONE); 376 if (rc != EOK) 377 return rc; 378 379 *value = uint16_t_le2host(*(uint16_t *)(b->data + offset % BPS(bs))); 380 381 rc = block_put(b); 382 383 return rc; 384 } 385 386 /** Get cluster from the first FAT. FAT32 version 387 * 388 * @param bs Buffer holding the boot sector for the file system. 389 * @param devmap_handle Device handle for the file system. 390 * @param clst Cluster which to get. 391 * @param value Output argument holding the value of the cluster. 392 * 393 * @return EOK or a negative error code. 394 */ 395 int 396 fat_get_cluster_fat32(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno, 397 fat_cluster_t clst, fat_cluster_t *value) 398 { 399 block_t *b; 400 aoff64_t offset; 401 int rc; 402 403 offset = (clst * FAT32_CLST_SIZE); 404 405 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + 406 offset / BPS(bs), BLOCK_FLAGS_NONE); 407 if (rc != EOK) 408 return rc; 409 410 *value = uint32_t_le2host(*(uint32_t *)(b->data + offset % BPS(bs)) & FAT32_MASK); 411 412 rc = block_put(b); 413 414 return rc; 415 } 416 417 418 /** Get cluster from the first FAT. 419 * 420 * @param bs Buffer holding the boot sector for the file system. 421 * @param devmap_handle Device handle for the file system. 422 * @param clst Cluster which to get. 423 * @param value Output argument holding the value of the cluster. 424 * 425 * @return EOK or a negative error code. 426 */ 427 int 428 fat_get_cluster(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno, 429 fat_cluster_t clst, fat_cluster_t *value) 430 { 431 int rc; 432 433 assert(fatno < FATCNT(bs)); 434 435 if (FAT_IS_FAT12(bs)) 436 rc = fat_get_cluster_fat12(bs, devmap_handle, fatno, clst, value); 437 else if (FAT_IS_FAT32(bs)) 438 rc = fat_get_cluster_fat32(bs, devmap_handle, fatno, clst, value); 439 else 440 rc = fat_get_cluster_fat16(bs, devmap_handle, fatno, clst, value); 441 442 return rc; 443 } 444 445 /** Set cluster in one instance of FAT. FAT12 version. 369 446 * 370 447 * @param bs Buffer holding the boot sector for the file system. … … 377 454 */ 378 455 int 379 fat_set_cluster (fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno,456 fat_set_cluster_fat12(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno, 380 457 fat_cluster_t clst, fat_cluster_t value) 381 458 { … … 384 461 int rc; 385 462 386 assert(fatno < FATCNT(bs)); 387 388 if (FAT_IS_FAT12(bs)) 389 offset = (clst + clst/2); 390 else 391 offset = (clst * FAT_CLST_SIZE(bs)); 463 offset = (clst + clst/2); 392 464 393 465 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + … … 398 470 value = host2uint32_t_le(value); 399 471 400 if (FAT_IS_FAT12(bs)) { 401 uint16_t temp; 402 bool border = false; 403 /* This cluster access spans a sector boundary. Check only for FAT12 */ 404 if (offset % BPS(bs)+1 == BPS(bs)) { 405 /* Is it last sector of FAT? */ 406 if (offset / BPS(bs) < SF(bs)) { 407 /* No. Reading next sector */ 408 rc = block_get(&b1, devmap_handle, 1 + RSCNT(bs) + 409 SF(bs)*fatno + offset / BPS(bs), BLOCK_FLAGS_NONE); 410 if (rc != EOK) { 411 block_put(b); 412 return rc; 413 } 414 /* 415 * Combining value with last byte of current sector and 416 * first byte of next sector 417 */ 418 temp = *(uint8_t *)(b->data + BPS(bs) - 1); 419 temp |= *(uint8_t *)(b1->data) << 8; 420 border = true; 472 uint16_t temp; 473 bool border = false; 474 /* This cluster access spans a sector boundary. Check only for FAT12 */ 475 if (offset % BPS(bs)+1 == BPS(bs)) { 476 /* Is it last sector of FAT? */ 477 if (offset / BPS(bs) < SF(bs)) { 478 /* No. Reading next sector */ 479 rc = block_get(&b1, devmap_handle, 1 + RSCNT(bs) + 480 SF(bs)*fatno + offset / BPS(bs), BLOCK_FLAGS_NONE); 481 if (rc != EOK) { 482 block_put(b); 483 return rc; 421 484 } 422 else { 423 /* Yes. It is last sector of fat */ 424 block_put(b); 425 return ERANGE; 426 } 427 } 428 else 429 temp = *(uint16_t *)(b->data + offset % BPS(bs)); 430 431 if (IS_ODD(clst)) { 432 temp &= 0x000f; 433 temp |= value << 4; 485 /* 486 * Combining value with last byte of current sector and 487 * first byte of next sector 488 */ 489 temp = *(uint8_t *)(b->data + BPS(bs) - 1); 490 temp |= *(uint8_t *)(b1->data) << 8; 491 border = true; 434 492 } 435 493 else { 436 temp &= 0xf000; 437 temp |= value & FAT12_MASK; 438 } 439 440 if (border) { 441 *(uint8_t *)(b->data + BPS(bs) - 1) = temp & 0xff; 442 *(uint8_t *)(b1->data) = temp >> 8; 443 b1->dirty = true; 444 } else 445 *(uint16_t *)(b->data + offset % BPS(bs)) = temp; 494 /* Yes. It is last sector of fat */ 495 block_put(b); 496 return ERANGE; 497 } 498 } 499 else 500 temp = *(uint16_t *)(b->data + offset % BPS(bs)); 501 502 if (IS_ODD(clst)) { 503 temp &= 0x000f; 504 temp |= value << 4; 446 505 } 447 506 else { 448 if (FAT_IS_FAT32(bs)) { 449 *(uint32_t *)(b->data + offset % BPS(bs)) &= 0xf0000000; 450 *(uint32_t *)(b->data + offset % BPS(bs)) |= (value & FAT32_MASK); 451 } else 452 *(uint16_t *)(b->data + offset % BPS(bs)) = value; 453 } 507 temp &= 0xf000; 508 temp |= value & FAT12_MASK; 509 } 510 511 if (border) { 512 *(uint8_t *)(b->data + BPS(bs) - 1) = temp & 0xff; 513 *(uint8_t *)(b1->data) = temp >> 8; 514 b1->dirty = true; 515 } else 516 *(uint16_t *)(b->data + offset % BPS(bs)) = temp; 454 517 455 518 if (b1 && b1->dirty) { … … 463 526 b->dirty = true; /* need to sync block */ 464 527 rc = block_put(b); 528 return rc; 529 } 530 531 /** Set cluster in one instance of FAT. FAT16 version. 532 * 533 * @param bs Buffer holding the boot sector for the file system. 534 * @param devmap_handle Device handle for the file system. 535 * @param fatno Number of the FAT instance where to make the change. 536 * @param clst Cluster which is to be set. 537 * @param value Value to set the cluster with. 538 * 539 * @return EOK on success or a negative error code. 540 */ 541 int 542 fat_set_cluster_fat16(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno, 543 fat_cluster_t clst, fat_cluster_t value) 544 { 545 block_t *b; 546 aoff64_t offset; 547 int rc; 548 549 offset = (clst * FAT16_CLST_SIZE); 550 551 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + 552 offset / BPS(bs), BLOCK_FLAGS_NONE); 553 if (rc != EOK) 554 return rc; 555 556 *(uint16_t *)(b->data + offset % BPS(bs)) = host2uint32_t_le(value); 557 558 b->dirty = true; /* need to sync block */ 559 rc = block_put(b); 560 return rc; 561 } 562 563 /** Set cluster in one instance of FAT. FAT32 version. 564 * 565 * @param bs Buffer holding the boot sector for the file system. 566 * @param devmap_handle Device handle for the file system. 567 * @param fatno Number of the FAT instance where to make the change. 568 * @param clst Cluster which is to be set. 569 * @param value Value to set the cluster with. 570 * 571 * @return EOK on success or a negative error code. 572 */ 573 int 574 fat_set_cluster_fat32(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno, 575 fat_cluster_t clst, fat_cluster_t value) 576 { 577 block_t *b; 578 aoff64_t offset; 579 int rc; 580 581 offset = (clst * FAT32_CLST_SIZE); 582 583 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + 584 offset / BPS(bs), BLOCK_FLAGS_NONE); 585 if (rc != EOK) 586 return rc; 587 588 value = host2uint32_t_le(value); 589 *(uint32_t *)(b->data + offset % BPS(bs)) &= 0xf0000000; 590 *(uint32_t *)(b->data + offset % BPS(bs)) |= (value & FAT32_MASK); 591 592 b->dirty = true; /* need to sync block */ 593 rc = block_put(b); 594 return rc; 595 } 596 597 /** Set cluster in one instance of FAT. 598 * 599 * @param bs Buffer holding the boot sector for the file system. 600 * @param devmap_handle Device handle for the file system. 601 * @param fatno Number of the FAT instance where to make the change. 602 * @param clst Cluster which is to be set. 603 * @param value Value to set the cluster with. 604 * 605 * @return EOK on success or a negative error code. 606 */ 607 int 608 fat_set_cluster(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno, 609 fat_cluster_t clst, fat_cluster_t value) 610 { 611 int rc; 612 613 assert(fatno < FATCNT(bs)); 614 615 if (FAT_IS_FAT12(bs)) 616 rc = fat_set_cluster_fat12(bs, devmap_handle, fatno, clst, value); 617 else if (FAT_IS_FAT32(bs)) 618 rc = fat_set_cluster_fat32(bs, devmap_handle, fatno, clst, value); 619 else 620 rc = fat_set_cluster_fat16(bs, devmap_handle, fatno, clst, value); 621 465 622 return rc; 466 623 } -
uspace/srv/fs/fat/fat_fat.h
ra8c14aa r88a27f1 44 44 #define FAT_CLST_FIRST 0x0002 45 45 46 #define FAT12_CLST_BAD 0x0ff747 #define FAT12_CLST_LAST1 0x0ff848 #define FAT12_CLST_LAST8 0x0fff49 #define FAT16_CLST_BAD 0xfff750 #define FAT16_CLST_LAST1 0xfff851 #define FAT16_CLST_LAST8 0xffff52 46 #define FAT32_CLST_BAD 0x0ffffff7 53 47 #define FAT32_CLST_LAST1 0x0ffffff8 … … 86 80 #define FAT_IS_FAT32(bs) (CC(bs) >= FAT16_CLST_MAX) 87 81 88 #define FAT_CLST_LAST1(bs) \89 (FAT_IS_FAT12(bs) ? FAT12_CLST_LAST1 : \90 (FAT_IS_FAT32(bs) ? FAT32_CLST_LAST1 : FAT16_CLST_LAST1))91 #define FAT_CLST_LAST8(bs) \92 (FAT_IS_FAT12(bs) ? FAT12_CLST_LAST8 : \93 (FAT_IS_FAT32(bs) ? FAT32_CLST_LAST8 : FAT16_CLST_LAST8))94 #define FAT_CLST_BAD(bs) \95 (FAT_IS_FAT12(bs) ? FAT12_CLST_BAD : \96 (FAT_IS_FAT32(bs) ? FAT32_CLST_BAD : FAT16_CLST_BAD))97 98 82 #define FAT_CLST_SIZE(bs) \ 99 83 (FAT_IS_FAT32(bs) ? FAT32_CLST_SIZE : FAT16_CLST_SIZE) … … 102 86 (FAT_IS_FAT12(bs) ? FAT12_MASK : \ 103 87 (FAT_IS_FAT32(bs) ? FAT32_MASK : FAT16_MASK)) 88 89 #define FAT_CLST_LAST1(bs) (FAT32_CLST_LAST1 & FAT_MASK((bs))) 90 #define FAT_CLST_LAST8(bs) (FAT32_CLST_LAST8 & FAT_MASK((bs))) 91 #define FAT_CLST_BAD(bs) (FAT32_CLST_BAD & FAT_MASK((bs))) 104 92 105 93 #define FAT_ROOT_CLST(bs) \ … … 133 121 extern int fat_alloc_shadow_clusters(struct fat_bs *, devmap_handle_t, 134 122 fat_cluster_t *, unsigned); 123 extern int fat_get_cluster_fat12(struct fat_bs *, devmap_handle_t, unsigned, 124 fat_cluster_t, fat_cluster_t *); 125 extern int fat_get_cluster_fat16(struct fat_bs *, devmap_handle_t, unsigned, 126 fat_cluster_t, fat_cluster_t *); 127 extern int fat_get_cluster_fat32(struct fat_bs *, devmap_handle_t, unsigned, 128 fat_cluster_t, fat_cluster_t *); 135 129 extern int fat_get_cluster(struct fat_bs *, devmap_handle_t, unsigned, 136 130 fat_cluster_t, fat_cluster_t *); 131 extern int fat_set_cluster_fat12(struct fat_bs *, devmap_handle_t, unsigned, 132 fat_cluster_t, fat_cluster_t); 133 extern int fat_set_cluster_fat16(struct fat_bs *, devmap_handle_t, unsigned, 134 fat_cluster_t, fat_cluster_t); 135 extern int fat_set_cluster_fat32(struct fat_bs *, devmap_handle_t, unsigned, 136 fat_cluster_t, fat_cluster_t); 137 137 extern int fat_set_cluster(struct fat_bs *, devmap_handle_t, unsigned, 138 138 fat_cluster_t, fat_cluster_t); -
uspace/srv/fs/fat/fat_ops.c
ra8c14aa r88a27f1 105 105 node->dirty = false; 106 106 node->lastc_cached_valid = false; 107 node->lastc_cached_value = FAT 16_CLST_LAST1;107 node->lastc_cached_value = FAT32_CLST_LAST1; 108 108 node->currc_cached_valid = false; 109 109 node->currc_cached_bn = 0; 110 node->currc_cached_value = FAT 16_CLST_LAST1;110 node->currc_cached_value = FAT32_CLST_LAST1; 111 111 } 112 112
Note:
See TracChangeset
for help on using the changeset viewer.