Changeset 5d5863c in mainline for uspace/srv/fs/exfat/exfat_fat.c


Ignore:
Timestamp:
2011-08-14T09:23:46Z (13 years ago)
Author:
Oleg Romanenko <romanenko.oleg@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
25c60f4
Parents:
5f0e16e4
Message:

exFAT: move bitmap_* function to separate file exfat_bitmap.c

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/exfat/exfat_fat.c

    r5f0e16e4 r5d5863c  
    3434/**
    3535 * @file        exfat_fat.c
    36  * @brief       Functions that manipulate the File Allocation Tables.
     36 * @brief       Functions that manipulate the File Allocation Table.
    3737 */
    3838
     
    169169}
    170170
    171 /** Read block from file located on a FAT file system.
     171/** Read block from file located on a exFAT file system.
    172172 *
    173173 * @param block         Pointer to a block pointer for storing result.
     
    476476}
    477477
    478 int bitmap_is_free(exfat_bs_t *bs, devmap_handle_t devmap_handle,
    479     exfat_cluster_t clst)
    480 {
    481         /* TODO */
    482         return EOK;
    483 }
    484 
    485 int bitmap_set_cluster(exfat_bs_t *bs, devmap_handle_t devmap_handle,
    486     exfat_cluster_t firstc)
    487 {
    488         /* TODO */
    489         return EOK;
    490 }
    491 
    492 int bitmap_clear_cluster(exfat_bs_t *bs, devmap_handle_t devmap_handle,
    493     exfat_cluster_t firstc)
    494 {
    495         /* TODO */
    496         return EOK;
    497 }
    498 
    499 int bitmap_set_clusters(exfat_bs_t *bs, devmap_handle_t devmap_handle,
    500     exfat_cluster_t firstc, exfat_cluster_t count)
    501 {
    502         int rc;
    503         exfat_cluster_t clst;
    504         clst = firstc;
    505 
    506         while (clst < firstc+count ) {
    507                 rc = bitmap_set_cluster(bs, devmap_handle, clst);
    508                 if (rc != EOK) {
    509                         if ((clst-firstc) > 0)
    510                                 (void) bitmap_clear_clusters(bs, devmap_handle, firstc, clst-firstc);
    511                         return rc;
    512                 }
    513                 clst++;
    514         }
    515         return EOK;
    516 }
    517 
    518 int bitmap_clear_clusters(exfat_bs_t *bs, devmap_handle_t devmap_handle,
    519     exfat_cluster_t firstc, exfat_cluster_t count)
    520 {
    521         int rc;
    522         exfat_cluster_t clst;
    523         clst = firstc;
    524 
    525         while (clst < firstc+count ) {
    526                 rc = bitmap_clear_cluster(bs, devmap_handle, clst);
    527                 if (rc != EOK)
    528                         return rc;
    529                 clst++;
    530         }
    531         return EOK;
    532 }
    533 
    534 int bitmap_alloc_clusters(exfat_bs_t *bs, devmap_handle_t devmap_handle,
    535     exfat_cluster_t *firstc, exfat_cluster_t count)
    536 {
    537         exfat_cluster_t startc, endc;
    538         startc = EXFAT_CLST_FIRST;
    539 
    540         while (startc < DATA_CNT(bs)+2) {
    541                 if (bitmap_is_free(bs, devmap_handle, startc) == EOK) {
    542                         endc = startc+1;
    543                         while (bitmap_is_free(bs, devmap_handle, endc) == EOK) {
    544                                 if ((endc - startc)+1 == count){
    545                                         *firstc = startc;
    546                                         return bitmap_set_clusters(bs, devmap_handle, startc, count);
    547                                 }
    548                                 else
    549                                         endc++;
    550                         }
    551                         startc = endc+1;
    552                 }
    553                 else
    554                         startc++;
    555         }
    556         return ENOSPC;
    557 }
    558 
    559 
    560 int bitmap_append_clusters(exfat_bs_t *bs, exfat_node_t *nodep,
    561     exfat_cluster_t count)
    562 {
    563         if (nodep->firstc == 0) {
    564                 return bitmap_alloc_clusters(bs, nodep->idx->devmap_handle,
    565                     &nodep->firstc, count);
    566         } else {
    567                 exfat_cluster_t lastc, clst;
    568                 lastc = nodep->firstc + ROUND_UP(nodep->size, BPC(bs)) / BPC(bs) - 1;
    569 
    570                 clst = lastc+1;
    571                 while (bitmap_is_free(bs, nodep->idx->devmap_handle, clst) == EOK) {
    572                         if ((clst - lastc) == count){
    573                                 return bitmap_set_clusters(bs, nodep->idx->devmap_handle,
    574                                     lastc+1, count);
    575                         }
    576                         else
    577                                 clst++;
    578                 }
    579                 return ENOSPC;
    580         }
    581 }
    582 
    583 
    584 int bitmap_free_clusters(exfat_bs_t *bs, exfat_node_t *nodep,
    585     exfat_cluster_t count)
    586 {
    587         exfat_cluster_t lastc;
    588         lastc = nodep->firstc + ROUND_UP(nodep->size, BPC(bs)) / BPC(bs) - 1;
    589         lastc -= count;
    590 
    591         return bitmap_clear_clusters(bs, nodep->idx->devmap_handle, lastc+1, count);
    592 }
    593 
    594 
    595 int bitmap_replicate_clusters(exfat_bs_t *bs, exfat_node_t *nodep)
    596 {
    597         int rc;
    598         exfat_cluster_t lastc, clst;
    599         devmap_handle_t devmap_handle = nodep->idx->devmap_handle;
    600         lastc = nodep->firstc + ROUND_UP(nodep->size, BPC(bs)) / BPC(bs) - 1;
    601 
    602         for (clst = nodep->firstc; clst < lastc; clst++) {
    603                 rc = exfat_set_cluster(bs, devmap_handle, clst, clst+1);
    604                 if (rc != EOK)
    605                         return rc;
    606         }
    607 
    608         return exfat_set_cluster(bs, devmap_handle, lastc, EXFAT_CLST_EOF);
    609 }
    610 
    611 
    612 
    613478/** Perform basic sanity checks on the file system.
    614479 *
     
    619484int exfat_sanity_check(exfat_bs_t *bs, devmap_handle_t devmap_handle)
    620485{
     486        /* TODO */
    621487        return EOK;
    622488}
Note: See TracChangeset for help on using the changeset viewer.