Changeset a86e4f8 in mainline
- Timestamp:
- 2011-07-20T12:23:05Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1f1d96a
- Parents:
- 5dac8ab
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/exfat/exfat_ops.c
r5dac8ab ra86e4f8 40 40 #include "exfat_fat.h" 41 41 #include "exfat_dentry.h" 42 #include "exfat_directory.h" 42 43 #include "../../vfs/vfs.h" 43 44 #include <libfs.h> … … 237 238 } 238 239 240 static int exfat_node_get_new_by_pos(exfat_node_t **nodepp, 241 devmap_handle_t devmap_handle, exfat_cluster_t pfc, unsigned pdi) 242 { 243 exfat_idx_t *idxp = exfat_idx_get_by_pos(devmap_handle, pfc, pdi); 244 if (!idxp) 245 return ENOMEM; 246 if (exfat_node_get_new(nodepp) != EOK) 247 return ENOMEM; 248 (*nodepp)->idx = idxp; 249 idxp->nodep = *nodepp; 250 return EOK; 251 } 252 253 239 254 /** Internal version of exfat_node_get(). 240 255 * … … 368 383 return exfat_node_get(rfn, devmap_handle, EXFAT_BITMAP_IDX); 369 384 } 370 385 */ 386 /* 371 387 int exfat_uctable_get(fs_node_t **rfn, devmap_handle_t devmap_handle) 372 388 { … … 505 521 */ 506 522 523 /* Print debug info */ 524 static void exfat_fsinfo(exfat_bs_t *bs, devmap_handle_t devmap_handle) 525 { 526 printf("exFAT file system mounted\n"); 527 printf("Version: %d.%d\n", bs->version.major, bs->version.minor); 528 printf("Volume serial: %d\n", uint32_t_le2host(bs->volume_serial)); 529 printf("Volume first sector: %lld\n", VOL_FS(bs)); 530 printf("Volume sectors: %lld\n", VOL_CNT(bs)); 531 printf("FAT first sector: %d\n", FAT_FS(bs)); 532 printf("FAT sectors: %d\n", FAT_CNT(bs)); 533 printf("Data first sector: %d\n", DATA_FS(bs)); 534 printf("Data sectors: %d\n", DATA_CNT(bs)); 535 printf("Root dir first cluster: %d\n", ROOT_FC(bs)); 536 printf("Bytes per sector: %d\n", BPS(bs)); 537 printf("Sectors per cluster: %d\n", SPC(bs)); 538 printf("KBytes per cluster: %d\n", SPC(bs)*BPS(bs)/1024); 539 540 int i, rc; 541 exfat_cluster_t clst; 542 for (i=0; i<6; i++) { 543 rc = fat_get_cluster(bs, devmap_handle, i, &clst); 544 if (rc != EOK) 545 return; 546 printf("Clst %d: %x\n", i, clst); 547 } 548 } 549 507 550 void exfat_mounted(ipc_callid_t rid, ipc_call_t *request) 508 551 { 509 552 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 553 exfat_node_t *rootp=NULL, *bitmapp=NULL, *uctablep=NULL; 510 554 enum cache_mode cmode; 511 555 exfat_bs_t *bs; … … 545 589 /* get the buffer with the boot sector */ 546 590 bs = block_bb_get(devmap_handle); 547 548 (void) bs;549 591 550 592 /* Initialize the block cache */ 551 rc = block_cache_init(devmap_handle, B S_SIZE, 0 /* XXX */, cmode);593 rc = block_cache_init(devmap_handle, BPS(bs), 0 /* XXX */, cmode); 552 594 if (rc != EOK) { 553 595 block_fini(devmap_handle); … … 574 616 575 617 /* Initialize the root node. */ 576 fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t)); 577 if (!rfn) { 618 rc = exfat_node_get_new_by_pos(&rootp, devmap_handle, EXFAT_ROOT_PAR, 619 EXFAT_ROOT_POS); 620 if (rc!=EOK) { 578 621 (void) block_cache_fini(devmap_handle); 579 622 block_fini(devmap_handle); … … 582 625 return; 583 626 } 584 585 fs_node_initialize(rfn); 586 exfat_node_t *rootp = (exfat_node_t *)malloc(sizeof(exfat_node_t)); 587 if (!rootp) { 588 free(rfn); 627 assert(rootp->idx->index == EXFAT_ROOT_IDX); 628 629 rootp->type = EXFAT_DIRECTORY; 630 rootp->firstc = ROOT_FC(bs); 631 rootp->fragmented = true; 632 rootp->refcnt = 1; 633 rootp->lnkcnt = 0; /* FS root is not linked */ 634 635 uint32_t clusters; 636 rc = fat_clusters_get(&clusters, bs, devmap_handle, rootp->firstc); 637 if (rc != EOK) { 638 free(rootp); 639 (void) block_cache_fini(devmap_handle); 640 block_fini(devmap_handle); 641 exfat_idx_fini_by_devmap_handle(devmap_handle); 642 async_answer_0(rid, ENOTSUP); 643 return; 644 } 645 rootp->size = BPS(bs) * SPC(bs) * clusters; 646 fibril_mutex_unlock(&rootp->idx->lock); 647 648 /* Open root directory and looking for Bitmap and UC-Table */ 649 exfat_directory_t di; 650 exfat_dentry_t *de; 651 rc = exfat_directory_open(rootp, &di); 652 if (rc != EOK) { 653 free(rootp); 654 (void) block_cache_fini(devmap_handle); 655 block_fini(devmap_handle); 656 exfat_idx_fini_by_devmap_handle(devmap_handle); 657 async_answer_0(rid, ENOTSUP); 658 return; 659 } 660 661 /* Initialize the bitmap node. */ 662 rc = exfat_directory_find(&di, EXFAT_DENTRY_BITMAP, &de); 663 if (rc != EOK) { 664 free(rootp); 665 (void) block_cache_fini(devmap_handle); 666 block_fini(devmap_handle); 667 exfat_idx_fini_by_devmap_handle(devmap_handle); 668 async_answer_0(rid, ENOTSUP); 669 return; 670 } 671 672 rc = exfat_node_get_new_by_pos(&bitmapp, devmap_handle, rootp->firstc, 673 di.pos); 674 if (rc!=EOK) { 675 free(rootp); 589 676 (void) block_cache_fini(devmap_handle); 590 677 block_fini(devmap_handle); … … 593 680 return; 594 681 } 595 596 exfat_node_initialize(rootp); 597 598 exfat_idx_t *ridxp = exfat_idx_get_by_pos(devmap_handle, EXFAT_ROOT_PAR, 0); 599 if (!ridxp) { 600 free(rfn); 682 assert(bitmapp->idx->index == EXFAT_BITMAP_IDX); 683 fibril_mutex_unlock(&bitmapp->idx->lock); 684 685 bitmapp->type = EXFAT_BITMAP; 686 bitmapp->firstc = de->bitmap.firstc; 687 bitmapp->fragmented = true; 688 bitmapp->refcnt = 1; 689 bitmapp->lnkcnt = 0; 690 bitmapp->size = de->bitmap.size; 691 692 /* Initialize the uctable node. */ 693 rc = exfat_directory_seek(&di, 0); 694 if (rc != EOK) { 601 695 free(rootp); 696 free(bitmapp); 697 (void) block_cache_fini(devmap_handle); 698 block_fini(devmap_handle); 699 exfat_idx_fini_by_devmap_handle(devmap_handle); 700 async_answer_0(rid, ENOTSUP); 701 return; 702 } 703 704 rc = exfat_directory_find(&di, EXFAT_DENTRY_UCTABLE, &de); 705 if (rc != EOK) { 706 free(rootp); 707 free(bitmapp); 708 (void) block_cache_fini(devmap_handle); 709 block_fini(devmap_handle); 710 exfat_idx_fini_by_devmap_handle(devmap_handle); 711 async_answer_0(rid, ENOTSUP); 712 return; 713 } 714 715 rc = exfat_node_get_new_by_pos(&uctablep, devmap_handle, rootp->firstc, 716 di.pos); 717 if (rc!=EOK) { 718 free(rootp); 719 free(bitmapp); 602 720 (void) block_cache_fini(devmap_handle); 603 721 block_fini(devmap_handle); … … 606 724 return; 607 725 } 608 assert(ridxp->index == 0); 609 /* ridxp->lock held */ 610 611 rootp->type = EXFAT_DIRECTORY; 612 rootp->firstc = ROOT_ST(bs); 613 rootp->refcnt = 1; 614 rootp->lnkcnt = 0; /* FS root is not linked */ 615 rootp->idx = ridxp; 616 ridxp->nodep = rootp; 617 rootp->bp = rfn; 618 rfn->data = rootp; 619 620 fibril_mutex_unlock(&ridxp->lock); 621 622 /* TODO */ 623 /* We should intitalize bitmap and uctable nodes next to the root node */ 624 /* HERE!!! */ 625 626 /* async_answer_0(rid, EOK); */ 627 async_answer_3(rid, EOK, ridxp->index, rootp->size, rootp->lnkcnt); 726 assert(uctablep->idx->index == EXFAT_UCTABLE_IDX); 727 fibril_mutex_unlock(&uctablep->idx->lock); 728 729 uctablep->type = EXFAT_UCTABLE; 730 uctablep->firstc = de->uctable.firstc; 731 uctablep->fragmented = true; 732 uctablep->refcnt = 1; 733 uctablep->lnkcnt = 0; 734 uctablep->size = de->uctable.size; 735 736 rc = exfat_directory_close(&di); 737 if (rc!=EOK) { 738 free(rootp); 739 free(bitmapp); 740 free(uctablep); 741 (void) block_cache_fini(devmap_handle); 742 block_fini(devmap_handle); 743 exfat_idx_fini_by_devmap_handle(devmap_handle); 744 async_answer_0(rid, ENOMEM); 745 return; 746 } 747 748 exfat_fsinfo(bs, devmap_handle); 749 printf("Root dir size: %lld\n", rootp->size); 750 751 async_answer_3(rid, EOK, rootp->idx->index, rootp->size, rootp->lnkcnt); 628 752 } 629 753 … … 681 805 } 682 806 807 /* 808 int bitmap_is_allocated(exfat_bs_t *bs, devmap_handle_t devmap_handle, 809 exfat_cluster_t clst, bool *status) 810 { 811 fs_node_t *fn; 812 exfat_node_t *bitmap; 813 int rc; 814 815 rc = exfat_bitmap_get(&fn, devmap_handle); 816 if (rc != EOK) 817 return rc; 818 819 nbitmap = EXFAT_NODE(fn); 820 821 822 return EOK; 823 } 824 */ 683 825 684 826 /**
Note:
See TracChangeset
for help on using the changeset viewer.