Changeset 6c8d267 in mainline


Ignore:
Timestamp:
2008-11-09T14:12:20Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
913a821c
Parents:
24d6efc
Message:

Simplify the fat_cluster_walk() interface.
Introduce the bn_t type for holding block offsets.

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libblock/libblock.c

    r24d6efc r6c8d267  
    300300 * @return                      Block structure.
    301301 */
    302 block_t *block_get(dev_handle_t dev_handle, off_t boff)
     302block_t *block_get(dev_handle_t dev_handle, bn_t boff)
    303303{
    304304        devcon_t *devcon;
  • uspace/lib/libblock/libblock.h

    r24d6efc r6c8d267  
    4545#include <libadt/list.h>
    4646
     47typedef unsigned bn_t;  /**< Block number type. */
     48
    4749typedef struct block {
    4850        /** Futex protecting the reference count. */
     
    5759        dev_handle_t dev_handle;
    5860        /** Block offset on the block device. Counted in 'size'-byte blocks. */
    59         off_t boff;
     61        bn_t boff;
    6062        /** Size of the block. */
    6163        size_t size;
     
    7678extern int block_cache_init(dev_handle_t, size_t, unsigned);
    7779
    78 extern block_t *block_get(dev_handle_t, off_t);
     80extern block_t *block_get(dev_handle_t, bn_t);
    7981extern void block_put(block_t *);
    8082
  • uspace/srv/fs/fat/fat_fat.c

    r24d6efc r6c8d267  
    6060 * @param dev_handle    Device handle of the device with the file.
    6161 * @param firstc        First cluster to start the walk with.
    62  * @param penult        If non-NULL, output argument hodling the
    63  *                      the penultimate cluster visited.
    64  * @param ult           If non-NULL, output argument holding the
    65  *                      ultimate cluster visited.
     62 * @param lastc         If non-NULL, output argument hodling the last cluster number visited.
    6663 * @param max_clusters  Maximum number of clusters to visit.   
    6764 *
     
    7067uint16_t
    7168fat_cluster_walk(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc,
    72     fat_cluster_t *penult, fat_cluster_t *ult, uint16_t max_clusters)
     69    fat_cluster_t *lastc, uint16_t max_clusters)
    7370{
    7471        block_t *b;
     
    8380        if (firstc == FAT_CLST_RES0) {
    8481                /* No space allocated to the file. */
    85                 if (ult)
    86                         *ult = firstc;
     82                if (lastc)
     83                        *lastc = firstc;
    8784                return 0;
    8885        }
    8986
    90         /* At this point, the meaning of penult is not well-defined. */
    91         if (penult)
    92                 *penult = FAT_CLST_RES0;
    93 
    9487        while (clst < FAT_CLST_LAST1 && clusters < max_clusters) {
    95                 unsigned fsec;  /* sector offset relative to FAT1 */
     88                bn_t fsec;      /* sector offset relative to FAT1 */
    9689                unsigned fidx;  /* FAT1 entry index */
    9790
    9891                assert(clst >= FAT_CLST_FIRST);
    99                 if (penult)
    100                         *penult = clst; /* remember the penultimate cluster */
     92                if (lastc)
     93                        *lastc = clst;  /* remember the last cluster number */
    10194                fsec = (clst * sizeof(fat_cluster_t)) / bps;
    10295                fidx = clst % (bps / sizeof(fat_cluster_t));
     
    109102        }
    110103
    111         if (ult)
    112                 *ult = clst;
     104        if (lastc && clst < FAT_CLST_LAST1)
     105                *lastc = clst;
    113106
    114107        return clusters;
     
    121114 * @param firstc        First cluster used by the file. Can be zero if the file
    122115 *                      is empty.
    123  * @param offset        Offset in blocks.
     116 * @param bn            Block number.
    124117 *
    125118 * @return              Block structure holding the requested block.
     
    127120block_t *
    128121_fat_block_get(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc,
    129     off_t offset)
     122    bn_t bn)
    130123{
    131124        block_t *b;
     
    150143        if (firstc == FAT_CLST_ROOT) {
    151144                /* root directory special case */
    152                 assert(offset < rds);
    153                 b = block_get(dev_handle, rscnt + bs->fatcnt * sf + offset);
     145                assert(bn < rds);
     146                b = block_get(dev_handle, rscnt + bs->fatcnt * sf + bn);
    154147                return b;
    155148        }
    156149
    157         max_clusters = offset / bs->spc;
    158         clusters = fat_cluster_walk(bs, dev_handle, firstc, NULL, &lastc,
     150        max_clusters = bn / bs->spc;
     151        clusters = fat_cluster_walk(bs, dev_handle, firstc, &lastc,
    159152            max_clusters);
    160153        assert(clusters == max_clusters);
    161154
    162155        b = block_get(dev_handle, ssa + (lastc - FAT_CLST_FIRST) * bs->spc +
    163             offset % bs->spc);
     156            bn % bs->spc);
    164157
    165158        return b;
     
    362355
    363356        if (fat_cluster_walk(bs, nodep->idx->dev_handle, nodep->firstc, &lcl,
    364             NULL, (uint16_t) -1) == 0) {
     357            (uint16_t) -1) == 0) {
    365358                /* No clusters allocated to the node yet. */
    366359                nodep->firstc = host2uint16_t_le(mcl);
  • uspace/srv/fs/fat/fat_fat.h

    r24d6efc r6c8d267  
    3636#include "../../vfs/vfs.h"
    3737#include <stdint.h>
     38#include <libblock.h>
    3839
    3940#define FAT1            0
     
    5960
    6061#define fat_clusters_get(bs, dh, fc) \
    61     fat_cluster_walk((bs), (dh), (fc), NULL, NULL, (uint16_t) -1)
    62 #define fat_block_get(bs, np, off) \
    63     _fat_block_get((bs), (np)->idx->dev_handle, (np)->firstc, (off))
     62    fat_cluster_walk((bs), (dh), (fc), NULL, (uint16_t) -1)
     63extern uint16_t fat_cluster_walk(struct fat_bs *, dev_handle_t, fat_cluster_t,
     64    fat_cluster_t *, uint16_t);
     65
     66#define fat_block_get(bs, np, bn) \
     67    _fat_block_get((bs), (np)->idx->dev_handle, (np)->firstc, (bn))
    6468
    6569extern struct block *_fat_block_get(struct fat_bs *, dev_handle_t,
    66     fat_cluster_t, off_t);
    67 extern uint16_t fat_cluster_walk(struct fat_bs *, dev_handle_t, fat_cluster_t,
    68     fat_cluster_t *, fat_cluster_t *, uint16_t);
     70    fat_cluster_t, bn_t);
    6971 
    7072extern void fat_append_clusters(struct fat_bs *, struct fat_node *,
Note: See TracChangeset for help on using the changeset viewer.