Subversion Repositories HelenOS

Rev

Rev 2889 | Rev 2925 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2889 Rev 2890
1
/*
1
/*
2
 * Copyright (c) 2008 Jakub Jermar
2
 * Copyright (c) 2008 Jakub Jermar
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup fs
29
/** @addtogroup fs
30
 * @{
30
 * @{
31
 */
31
 */
32
 
32
 
33
/**
33
/**
34
 * @file    fat_idx.c
34
 * @file    fat_idx.c
35
 * @brief   Layer for translating FAT entities to VFS node indices.
35
 * @brief   Layer for translating FAT entities to VFS node indices.
36
 */
36
 */
37
 
37
 
38
#include "fat.h"
38
#include "fat.h"
39
#include "../../vfs/vfs.h"
39
#include "../../vfs/vfs.h"
40
#include <errno.h>
40
#include <errno.h>
41
#include <string.h>
41
#include <string.h>
42
#include <libadt/hash_table.h>
42
#include <libadt/hash_table.h>
43
#include <libadt/list.h>
43
#include <libadt/list.h>
44
#include <assert.h>
44
#include <assert.h>
45
#include <futex.h>
45
#include <futex.h>
46
 
46
 
47
/** Each instance of this type describes one interval of freed VFS indices. */
47
/** Each instance of this type describes one interval of freed VFS indices. */
48
typedef struct {
48
typedef struct {
49
    link_t      link;
49
    link_t      link;
50
    fs_index_t  first;
50
    fs_index_t  first;
51
    fs_index_t  last;
51
    fs_index_t  last;
52
} freed_t;
52
} freed_t;
53
 
53
 
54
/**
54
/**
55
 * Each instance of this type describes state of all VFS indices that
55
 * Each instance of this type describes state of all VFS indices that
56
 * are currently unused.
56
 * are currently unused.
57
 */
57
 */
58
typedef struct {
58
typedef struct {
59
    link_t      link;
59
    link_t      link;
60
    dev_handle_t    dev_handle;
60
    dev_handle_t    dev_handle;
61
 
61
 
62
    /** Next unassigned index. */
62
    /** Next unassigned index. */
63
    fs_index_t  next;
63
    fs_index_t  next;
64
    /** Number of remaining unassigned indices. */
64
    /** Number of remaining unassigned indices. */
65
    uint64_t    remaining;
65
    uint64_t    remaining;
66
 
66
 
67
    /** Sorted list of intervals of freed indices. */
67
    /** Sorted list of intervals of freed indices. */
68
    link_t      freed_head;
68
    link_t      freed_head;
69
} unused_t;
69
} unused_t;
70
 
70
 
71
static LIST_INITIALIZE(unused_head);
71
static LIST_INITIALIZE(unused_head);
72
 
72
 
-
 
73
/**
73
/** Global hash table of all used fat_idx_t structures. */
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
 */
74
static hash_table_t used_hash;
78
static hash_table_t up_hash;
75
 
79
 
76
#define USED_HASH_BUCKETS_LOG   12
80
#define UPH_BUCKETS_LOG 12
77
#define USED_HASH_BUCKETS   (1 << USED_HASH_BUCKETS_LOG)
81
#define UPH_BUCKETS (1 << UPH_BUCKETS_LOG)
78
 
82
 
79
#define USED_HASH_DH_KEY    0
83
#define UPH_DH_KEY  0
80
#define USED_HASH_PFC_KEY   1
84
#define UPH_PFC_KEY 1
81
#define USED_HASH_PDI_KEY   2
85
#define UPH_PDI_KEY 2
82
 
86
 
83
static hash_index_t idx_hash(unsigned long key[])
87
static hash_index_t pos_hash(unsigned long key[])
84
{
88
{
85
    dev_handle_t dev_handle = (dev_handle_t)key[USED_HASH_DH_KEY];
89
    dev_handle_t dev_handle = (dev_handle_t)key[UPH_DH_KEY];
86
    fat_cluster_t pfc = (fat_cluster_t)key[USED_HASH_PFC_KEY];
90
    fat_cluster_t pfc = (fat_cluster_t)key[UPH_PFC_KEY];
87
    unsigned pdi = (unsigned)key[USED_HASH_PDI_KEY];
91
    unsigned pdi = (unsigned)key[UPH_PDI_KEY];
88
 
92
 
89
    hash_index_t h;
93
    hash_index_t h;
90
 
94
 
91
    /*
95
    /*
92
     * The least significant half of all bits are the least significant bits
96
     * The least significant half of all bits are the least significant bits
93
     * of the parent node's first cluster.
97
     * of the parent node's first cluster.
94
     *
98
     *
95
     * The least significant half of the most significant half of all bits
99
     * The least significant half of the most significant half of all bits
96
     * are the least significant bits of the node's dentry index within the
100
     * are the least significant bits of the node's dentry index within the
97
     * parent directory node.
101
     * parent directory node.
98
     *
102
     *
99
     * The most significant half of the most significant half of all bits
103
     * The most significant half of the most significant half of all bits
100
     * are the least significant bits of the device handle.
104
     * are the least significant bits of the device handle.
101
     */
105
     */
102
    h = pfc & ((USED_HASH_BUCKETS_LOG / 2) - 1);
106
    h = pfc & ((1 << (UPH_BUCKETS_LOG / 2)) - 1);
103
    h |= (pdi & ((USED_HASH_BUCKETS_LOG / 4) - 1)) <<
107
    h |= (pdi & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
104
        (USED_HASH_BUCKETS_LOG / 2);
108
        (UPH_BUCKETS_LOG / 2);
105
    h |= (dev_handle & ((USED_HASH_BUCKETS_LOG / 4) - 1)) <<
109
    h |= (dev_handle & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
106
        (3 * (USED_HASH_BUCKETS_LOG / 4));
110
        (3 * (UPH_BUCKETS_LOG / 4));
107
 
111
 
108
    return h;
112
    return h;
109
}
113
}
110
 
114
 
111
static int idx_compare(unsigned long key[], hash_count_t keys, link_t *item)
115
static int pos_compare(unsigned long key[], hash_count_t keys, link_t *item)
112
{
116
{
113
    dev_handle_t dev_handle = (dev_handle_t)key[USED_HASH_DH_KEY];
117
    dev_handle_t dev_handle = (dev_handle_t)key[UPH_DH_KEY];
114
    fat_cluster_t pfc = (fat_cluster_t)key[USED_HASH_PFC_KEY];
118
    fat_cluster_t pfc = (fat_cluster_t)key[UPH_PFC_KEY];
115
    unsigned pdi = (unsigned)key[USED_HASH_PDI_KEY];
119
    unsigned pdi = (unsigned)key[UPH_PDI_KEY];
116
    fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uh_link);
120
    fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uph_link);
117
 
121
 
118
    return (dev_handle == fidx->dev_handle) && (pfc == fidx->pfc) &&
122
    return (dev_handle == fidx->dev_handle) && (pfc == fidx->pfc) &&
119
        (pdi == fidx->pdi);
123
        (pdi == fidx->pdi);
120
}
124
}
121
 
125
 
-
 
126
static void pos_remove_callback(link_t *item)
-
 
127
{
-
 
128
    /* nothing to do */
-
 
129
}
-
 
130
 
-
 
131
static 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
 */
-
 
141
static 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
 
-
 
149
static 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
 
-
 
163
static 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
 
122
static void idx_remove_callback(link_t *item)
172
static void idx_remove_callback(link_t *item)
123
{
173
{
124
    /* nothing to do */
174
    /* nothing to do */
125
}
175
}
126
 
176
 
127
static hash_table_operations_t used_idx_ops = {
177
static hash_table_operations_t uih_ops = {
128
    .hash = idx_hash,
178
    .hash = idx_hash,
129
    .compare = idx_compare,
179
    .compare = idx_compare,
130
    .remove_callback = idx_remove_callback,
180
    .remove_callback = idx_remove_callback,
131
};
181
};
132
 
182
 
133
/** Allocate a VFS index which is not currently in use. */
183
/** Allocate a VFS index which is not currently in use. */
134
static bool fat_idx_alloc(dev_handle_t dev_handle, fs_index_t *index)
184
static bool fat_idx_alloc(dev_handle_t dev_handle, fs_index_t *index)
135
{
185
{
136
    link_t *l;
186
    link_t *l;
137
    unused_t *u;
187
    unused_t *u;
138
   
188
   
139
    assert(index);
189
    assert(index);
140
    for (l = unused_head.next; l != &unused_head; l = l->next) {
190
    for (l = unused_head.next; l != &unused_head; l = l->next) {
141
        u = list_get_instance(l, unused_t, link);
191
        u = list_get_instance(l, unused_t, link);
142
        if (u->dev_handle == dev_handle)
192
        if (u->dev_handle == dev_handle)
143
            goto hit;
193
            goto hit;
144
    }
194
    }
145
 
195
 
146
    /* dev_handle not found */
196
    /* dev_handle not found */
147
    return false;  
197
    return false;  
148
 
198
 
149
hit:
199
hit:
150
    if (list_empty(&u->freed_head)) {
200
    if (list_empty(&u->freed_head)) {
151
        if (u->remaining) {
201
        if (u->remaining) {
152
            /*
202
            /*
153
             * There are no freed indices, allocate one directly
203
             * There are no freed indices, allocate one directly
154
             * from the counter.
204
             * from the counter.
155
             */
205
             */
156
            *index = u->next++;
206
            *index = u->next++;
157
            --u->remaining;
207
            --u->remaining;
158
            return true;
208
            return true;
159
        }
209
        }
160
    } else {
210
    } else {
161
        /* There are some freed indices which we can reuse. */
211
        /* There are some freed indices which we can reuse. */
162
        freed_t *f = list_get_instance(u->freed_head.next, freed_t,
212
        freed_t *f = list_get_instance(u->freed_head.next, freed_t,
163
            link);
213
            link);
164
        *index = f->first;
214
        *index = f->first;
165
        if (f->first++ == f->last) {
215
        if (f->first++ == f->last) {
166
            /* Destroy the interval. */
216
            /* Destroy the interval. */
167
            list_remove(&f->link);
217
            list_remove(&f->link);
168
            free(f);
218
            free(f);
169
        }
219
        }
170
        return true;
220
        return true;
171
    }
221
    }
172
    /*
222
    /*
173
     * We ran out of indices, which is extremely unlikely with FAT16, but
223
     * We ran out of indices, which is extremely unlikely with FAT16, but
174
     * theoretically still possible (e.g. too many open unlinked nodes or
224
     * theoretically still possible (e.g. too many open unlinked nodes or
175
     * too many zero-sized nodes).
225
     * too many zero-sized nodes).
176
     */
226
     */
177
    return false;
227
    return false;
178
}
228
}
179
 
229
 
180
/** If possible, coalesce two intervals of freed indices. */
230
/** If possible, coalesce two intervals of freed indices. */
181
static void try_coalesce_intervals(link_t *l, link_t *r, link_t *cur)
231
static void try_coalesce_intervals(link_t *l, link_t *r, link_t *cur)
182
{
232
{
183
    freed_t *fl = list_get_instance(l, freed_t, link);
233
    freed_t *fl = list_get_instance(l, freed_t, link);
184
    freed_t *fr = list_get_instance(r, freed_t, link);
234
    freed_t *fr = list_get_instance(r, freed_t, link);
185
 
235
 
186
    if (fl->last + 1 == fr->first) {
236
    if (fl->last + 1 == fr->first) {
187
        if (cur == l) {
237
        if (cur == l) {
188
            fl->last = fr->last;
238
            fl->last = fr->last;
189
            list_remove(r);
239
            list_remove(r);
190
            free(r);
240
            free(r);
191
        } else {
241
        } else {
192
            fr->first = fl->first;
242
            fr->first = fl->first;
193
            list_remove(l);
243
            list_remove(l);
194
            free(l);
244
            free(l);
195
        }
245
        }
196
    }
246
    }
197
}
247
}
198
 
248
 
199
/** Free a VFS index, which is no longer in use. */
249
/** Free a VFS index, which is no longer in use. */
200
static void fat_idx_free(dev_handle_t dev_handle, fs_index_t index)
250
static void fat_idx_free(dev_handle_t dev_handle, fs_index_t index)
201
{
251
{
202
    link_t *l;
252
    link_t *l;
203
    unused_t *u;
253
    unused_t *u;
204
 
254
 
205
    for (l = unused_head.next; l != &unused_head; l = l->next) {
255
    for (l = unused_head.next; l != &unused_head; l = l->next) {
206
        u = list_get_instance(l, unused_t, link);
256
        u = list_get_instance(l, unused_t, link);
207
        if (u->dev_handle == dev_handle)
257
        if (u->dev_handle == dev_handle)
208
            goto hit;
258
            goto hit;
209
    }
259
    }
210
 
260
 
211
    /* should not happen */
261
    /* should not happen */
212
    assert(0);
262
    assert(0);
213
 
263
 
214
hit:
264
hit:
215
    if (u->next == index + 1) {
265
    if (u->next == index + 1) {
216
        /* The index can be returned directly to the counter. */
266
        /* The index can be returned directly to the counter. */
217
        u->next--;
267
        u->next--;
218
        u->remaining++;
268
        u->remaining++;
219
        return;
269
        return;
220
    } else {
270
    } else {
221
        /*
271
        /*
222
         * The index must be returned either to an existing freed
272
         * The index must be returned either to an existing freed
223
         * interval or a new interval must be created.
273
         * interval or a new interval must be created.
224
         */
274
         */
225
        link_t *lnk;
275
        link_t *lnk;
226
        freed_t *n;
276
        freed_t *n;
227
        for (lnk = u->freed_head.next; lnk != &u->freed_head;
277
        for (lnk = u->freed_head.next; lnk != &u->freed_head;
228
            lnk = lnk->next) {
278
            lnk = lnk->next) {
229
            freed_t *f = list_get_instance(lnk, freed_t, link);
279
            freed_t *f = list_get_instance(lnk, freed_t, link);
230
            if (f->first == index + 1) {
280
            if (f->first == index + 1) {
231
                f->first--;
281
                f->first--;
232
                if (lnk->prev != &u->freed_head)
282
                if (lnk->prev != &u->freed_head)
233
                    try_coalesce_intervals(lnk->prev, lnk,
283
                    try_coalesce_intervals(lnk->prev, lnk,
234
                        lnk);
284
                        lnk);
235
                return;
285
                return;
236
            }
286
            }
237
            if (f->last == index - 1) {
287
            if (f->last == index - 1) {
238
                f->last++;
288
                f->last++;
239
                if (lnk->next != &u->freed_head)
289
                if (lnk->next != &u->freed_head)
240
                    try_coalesce_intervals(lnk, lnk->next,
290
                    try_coalesce_intervals(lnk, lnk->next,
241
                        lnk);
291
                        lnk);
242
                return;
292
                return;
243
            }
293
            }
244
            if (index > f->first) {
294
            if (index > f->first) {
245
                n = malloc(sizeof(freed_t));
295
                n = malloc(sizeof(freed_t));
246
                /* TODO: sleep until allocation succeeds */
296
                /* TODO: sleep until allocation succeeds */
247
                assert(n);
297
                assert(n);
248
                link_initialize(&n->link);
298
                link_initialize(&n->link);
249
                n->first = index;
299
                n->first = index;
250
                n->last = index;
300
                n->last = index;
251
                list_insert_before(&n->link, lnk);
301
                list_insert_before(&n->link, lnk);
252
                return;
302
                return;
253
            }
303
            }
254
 
304
 
255
        }
305
        }
256
        /* The index will form the last interval. */
306
        /* The index will form the last interval. */
257
        n = malloc(sizeof(freed_t));
307
        n = malloc(sizeof(freed_t));
258
        /* TODO: sleep until allocation succeeds */
308
        /* TODO: sleep until allocation succeeds */
259
        assert(n);
309
        assert(n);
260
        link_initialize(&n->link);
310
        link_initialize(&n->link);
261
        n->first = index;
311
        n->first = index;
262
        n->last = index;
312
        n->last = index;
263
        list_append(&n->link, &u->freed_head);
313
        list_append(&n->link, &u->freed_head);
264
    }
314
    }
265
}
315
}
266
 
316
 
-
 
317
fat_idx_t *
267
fat_idx_t *fat_idx_map(dev_handle_t dev_handle, fat_cluster_t pfc, unsigned pdi)
318
fat_idx_get_by_pos(dev_handle_t dev_handle, fat_cluster_t pfc, unsigned pdi)
268
{
319
{
269
    fat_idx_t *fidx;
320
    fat_idx_t *fidx;
270
    link_t *l;
321
    link_t *l;
271
    unsigned long key[] = {
322
    unsigned long pkey[] = {
272
        [USED_HASH_DH_KEY] = dev_handle,
323
        [UPH_DH_KEY] = dev_handle,
273
        [USED_HASH_PFC_KEY] = pfc,
324
        [UPH_PFC_KEY] = pfc,
274
        [USED_HASH_PDI_KEY] = pdi,
325
        [UPH_PDI_KEY] = pdi,
275
    };
326
    };
276
 
327
 
277
    l = hash_table_find(&used_hash, key);
328
    l = hash_table_find(&up_hash, pkey);
278
    if (l) {
329
    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);
280
    } else {
331
    } else {
281
        fidx = (fat_idx_t *) malloc(sizeof(fat_idx_t));
332
        fidx = (fat_idx_t *) malloc(sizeof(fat_idx_t));
282
        if (!fidx) {
333
        if (!fidx) {
283
            return NULL;
334
            return NULL;
284
        }
335
        }
285
        if (!fat_idx_alloc(dev_handle, &fidx->index)) {
336
        if (!fat_idx_alloc(dev_handle, &fidx->index)) {
286
            free(fidx);
337
            free(fidx);
287
            return NULL;
338
            return NULL;
288
        }
339
        }
-
 
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);
289
        link_initialize(&fidx->uh_link);
347
        link_initialize(&fidx->uih_link);
290
        fidx->dev_handle = dev_handle;
348
        fidx->dev_handle = dev_handle;
291
        fidx->pfc = pfc;
349
        fidx->pfc = pfc;
292
        fidx->pdi = pdi;
350
        fidx->pdi = pdi;
293
        fidx->nodep = NULL;
351
        fidx->nodep = NULL;
-
 
352
 
294
        hash_table_insert(&used_hash, key, &fidx->uh_link);
353
        hash_table_insert(&up_hash, pkey, &fidx->uph_link);
-
 
354
        hash_table_insert(&ui_hash, ikey, &fidx->uih_link);
-
 
355
    }
-
 
356
 
-
 
357
    return fidx;
-
 
358
}
-
 
359
 
-
 
360
fat_idx_t *
-
 
361
fat_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);
295
    }
373
    }
296
 
374
 
297
    return fidx;
375
    return fidx;
298
}
376
}
299
 
377
 
300
 
378