Changeset 4797132 in mainline


Ignore:
Timestamp:
2008-05-08T19:23:36Z (17 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4573a79
Parents:
9a5ccfb3
Message:

Need a way to locate the FAT index structure by VFS index. Also fix code that
locates the FAT index structure by position in the file system namespace.

Location:
uspace/srv/fs/fat
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/fat/fat.h

    r9a5ccfb3 r4797132  
    176176 */
    177177typedef struct {
    178         /** Used indices hash table link. */
    179         link_t          uh_link;
     178        /** Used indices (position) hash table link. */
     179        link_t          uph_link;
     180        /** Used indices (index) hash table link. */
     181        link_t          uih_link;
    180182
    181183        dev_handle_t    dev_handle;
     
    218220extern void fat_lookup(ipc_callid_t, ipc_call_t *);
    219221
    220 extern fat_idx_t *fat_idx_map(dev_handle_t, fat_cluster_t, unsigned);
     222extern fat_idx_t *fat_idx_get_by_pos(dev_handle_t, fat_cluster_t, unsigned);
     223extern fat_idx_t *fat_idx_get_by_index(dev_handle_t, fs_index_t);
    221224
    222225#endif
  • uspace/srv/fs/fat/fat_idx.c

    r9a5ccfb3 r4797132  
    7171static LIST_INITIALIZE(unused_head);
    7272
    73 /** Global hash table of all used fat_idx_t structures. */
    74 static hash_table_t used_hash;
    75 
    76 #define USED_HASH_BUCKETS_LOG   12
    77 #define USED_HASH_BUCKETS       (1 << USED_HASH_BUCKETS_LOG)
    78 
    79 #define USED_HASH_DH_KEY        0
    80 #define USED_HASH_PFC_KEY       1
    81 #define USED_HASH_PDI_KEY       2
    82 
    83 static hash_index_t idx_hash(unsigned long key[])
    84 {
    85         dev_handle_t dev_handle = (dev_handle_t)key[USED_HASH_DH_KEY];
    86         fat_cluster_t pfc = (fat_cluster_t)key[USED_HASH_PFC_KEY];
    87         unsigned pdi = (unsigned)key[USED_HASH_PDI_KEY];
     73/**
     74 * Global hash table of all used fat_idx_t structures.
     75 * The index structures are hashed by the dev_handle, parent node's first
     76 * cluster and index within the parent directory.
     77 */
     78static hash_table_t up_hash;
     79
     80#define UPH_BUCKETS_LOG 12
     81#define UPH_BUCKETS     (1 << UPH_BUCKETS_LOG)
     82
     83#define UPH_DH_KEY      0
     84#define UPH_PFC_KEY     1
     85#define UPH_PDI_KEY     2
     86
     87static hash_index_t pos_hash(unsigned long key[])
     88{
     89        dev_handle_t dev_handle = (dev_handle_t)key[UPH_DH_KEY];
     90        fat_cluster_t pfc = (fat_cluster_t)key[UPH_PFC_KEY];
     91        unsigned pdi = (unsigned)key[UPH_PDI_KEY];
    8892
    8993        hash_index_t h;
     
    100104         * are the least significant bits of the device handle.
    101105         */
    102         h = pfc & ((USED_HASH_BUCKETS_LOG / 2) - 1);
    103         h |= (pdi & ((USED_HASH_BUCKETS_LOG / 4) - 1)) <<
    104             (USED_HASH_BUCKETS_LOG / 2);
    105         h |= (dev_handle & ((USED_HASH_BUCKETS_LOG / 4) - 1)) <<
    106             (3 * (USED_HASH_BUCKETS_LOG / 4));
     106        h = pfc & ((1 << (UPH_BUCKETS_LOG / 2)) - 1);
     107        h |= (pdi & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
     108            (UPH_BUCKETS_LOG / 2);
     109        h |= (dev_handle & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
     110            (3 * (UPH_BUCKETS_LOG / 4));
    107111
    108112        return h;
    109113}
    110114
    111 static int idx_compare(unsigned long key[], hash_count_t keys, link_t *item)
    112 {
    113         dev_handle_t dev_handle = (dev_handle_t)key[USED_HASH_DH_KEY];
    114         fat_cluster_t pfc = (fat_cluster_t)key[USED_HASH_PFC_KEY];
    115         unsigned pdi = (unsigned)key[USED_HASH_PDI_KEY];
    116         fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uh_link);
     115static int pos_compare(unsigned long key[], hash_count_t keys, link_t *item)
     116{
     117        dev_handle_t dev_handle = (dev_handle_t)key[UPH_DH_KEY];
     118        fat_cluster_t pfc = (fat_cluster_t)key[UPH_PFC_KEY];
     119        unsigned pdi = (unsigned)key[UPH_PDI_KEY];
     120        fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uph_link);
    117121
    118122        return (dev_handle == fidx->dev_handle) && (pfc == fidx->pfc) &&
     
    120124}
    121125
     126static void pos_remove_callback(link_t *item)
     127{
     128        /* nothing to do */
     129}
     130
     131static hash_table_operations_t uph_ops = {
     132        .hash = pos_hash,
     133        .compare = pos_compare,
     134        .remove_callback = pos_remove_callback,
     135};
     136
     137/**
     138 * Global hash table of all used fat_idx_t structures.
     139 * The index structures are hashed by the dev_handle and index.
     140 */
     141static hash_table_t ui_hash;
     142
     143#define UIH_BUCKETS_LOG 12
     144#define UIH_BUCKETS     (1 << UIH_BUCKETS_LOG)
     145
     146#define UIH_DH_KEY      0
     147#define UIH_INDEX_KEY   1
     148
     149static hash_index_t idx_hash(unsigned long key[])
     150{
     151        dev_handle_t dev_handle = (dev_handle_t)key[UIH_DH_KEY];
     152        fs_index_t index = (fs_index_t)key[UIH_INDEX_KEY];
     153
     154        hash_index_t h;
     155
     156        h = dev_handle & ((1 << (UIH_BUCKETS_LOG / 2)) - 1);
     157        h |= (index & ((1 << (UIH_BUCKETS_LOG / 2)) - 1)) <<
     158            (UIH_BUCKETS_LOG / 2);
     159
     160        return h;
     161}
     162
     163static int idx_compare(unsigned long key[], hash_count_t keys, link_t *item)
     164{
     165        dev_handle_t dev_handle = (dev_handle_t)key[UIH_DH_KEY];
     166        fs_index_t index = (fs_index_t)key[UIH_INDEX_KEY];
     167        fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uih_link);
     168
     169        return (dev_handle == fidx->dev_handle) && (index == fidx->index);
     170}
     171
    122172static void idx_remove_callback(link_t *item)
    123173{
     
    125175}
    126176
    127 static hash_table_operations_t used_idx_ops = {
     177static hash_table_operations_t uih_ops = {
    128178        .hash = idx_hash,
    129179        .compare = idx_compare,
     
    265315}
    266316
    267 fat_idx_t *fat_idx_map(dev_handle_t dev_handle, fat_cluster_t pfc, unsigned pdi)
     317fat_idx_t *
     318fat_idx_get_by_pos(dev_handle_t dev_handle, fat_cluster_t pfc, unsigned pdi)
    268319{
    269320        fat_idx_t *fidx;
    270321        link_t *l;
    271         unsigned long key[] = {
    272                 [USED_HASH_DH_KEY] = dev_handle,
    273                 [USED_HASH_PFC_KEY] = pfc,
    274                 [USED_HASH_PDI_KEY] = pdi,
     322        unsigned long pkey[] = {
     323                [UPH_DH_KEY] = dev_handle,
     324                [UPH_PFC_KEY] = pfc,
     325                [UPH_PDI_KEY] = pdi,
    275326        };
    276327
    277         l = hash_table_find(&used_hash, key);
     328        l = hash_table_find(&up_hash, pkey);
    278329        if (l) {
    279                 fidx = hash_table_get_instance(l, fat_idx_t, uh_link);
     330                fidx = hash_table_get_instance(l, fat_idx_t, uph_link);
    280331        } else {
    281332                fidx = (fat_idx_t *) malloc(sizeof(fat_idx_t));
     
    287338                        return NULL;
    288339                }
    289                 link_initialize(&fidx->uh_link);
     340               
     341                unsigned long ikey[] = {
     342                        [UIH_DH_KEY] = dev_handle,
     343                        [UIH_INDEX_KEY] = fidx->index,
     344                };
     345       
     346                link_initialize(&fidx->uph_link);
     347                link_initialize(&fidx->uih_link);
    290348                fidx->dev_handle = dev_handle;
    291349                fidx->pfc = pfc;
    292350                fidx->pdi = pdi;
    293351                fidx->nodep = NULL;
    294                 hash_table_insert(&used_hash, key, &fidx->uh_link);
     352
     353                hash_table_insert(&up_hash, pkey, &fidx->uph_link);
     354                hash_table_insert(&ui_hash, ikey, &fidx->uih_link);
    295355        }
    296356
     
    298358}
    299359
     360fat_idx_t *
     361fat_idx_get_by_index(dev_handle_t dev_handle, fs_index_t index)
     362{
     363        fat_idx_t *fidx = NULL;
     364        link_t *l;
     365        unsigned long ikey[] = {
     366                [UIH_DH_KEY] = dev_handle,
     367                [UIH_INDEX_KEY] = index,
     368        };
     369
     370        l = hash_table_find(&ui_hash, ikey);
     371        if (l) {
     372                fidx = hash_table_get_instance(l, fat_idx_t, uih_link);
     373        }
     374
     375        return fidx;
     376}
     377
  • uspace/srv/fs/fat/fat_ops.c

    r9a5ccfb3 r4797132  
    309309                        if (strcmp(name, component) == 0) {
    310310                                /* hit */
    311                                 fat_idx_t *idx = fat_idx_map(
     311                                fat_idx_t *idx = fat_idx_get_by_pos(
    312312                                    parentp->idx->dev_handle, parentp->firstc,
    313313                                    i * dps + j);
     314                                if (!idx) {
     315                                        /*
     316                                         * Can happen if memory is low or if we
     317                                         * run out of 32-bit indices.
     318                                         */
     319                                        block_put(b);
     320                                        return NULL;
     321                                }
    314322                                void *node = fat_node_get(idx->dev_handle,
    315323                                    idx->index);
Note: See TracChangeset for help on using the changeset viewer.