Rev 3516 | Rev 3518 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3516 | Rev 3517 | ||
|---|---|---|---|
| Line 30... | Line 30... | ||
| 30 | * @{ |
30 | * @{ |
| 31 | */ |
31 | */ |
| 32 | 32 | ||
| 33 | /** |
33 | /** |
| 34 | * @file fat_fat.c |
34 | * @file fat_fat.c |
| 35 | * @brief Functions that manipulate the file allocation tables. |
35 | * @brief Functions that manipulate the File Allocation Tables. |
| 36 | */ |
36 | */ |
| 37 | 37 | ||
| 38 | #include "fat_fat.h" |
38 | #include "fat_fat.h" |
| 39 | #include "fat_dentry.h" |
39 | #include "fat_dentry.h" |
| 40 | #include "fat.h" |
40 | #include "fat.h" |
| Line 42... | Line 42... | ||
| 42 | #include <libfs.h> |
42 | #include <libfs.h> |
| 43 | #include <errno.h> |
43 | #include <errno.h> |
| 44 | #include <byteorder.h> |
44 | #include <byteorder.h> |
| 45 | #include <align.h> |
45 | #include <align.h> |
| 46 | #include <assert.h> |
46 | #include <assert.h> |
| - | 47 | #include <futex.h> |
|
| - | 48 | ||
| - | 49 | /** |
|
| - | 50 | * The fat_alloc_lock futex protects all copies of the File Allocation Table |
|
| - | 51 | * during allocation of clusters. The lock does not have to be held durring |
|
| - | 52 | * deallocation of clusters. |
|
| - | 53 | */ |
|
| - | 54 | static futex_t fat_alloc_lock = FUTEX_INITIALIZER; |
|
| 47 | 55 | ||
| 48 | block_t * |
56 | block_t * |
| 49 | _fat_block_get(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc, |
57 | _fat_block_get(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t firstc, |
| 50 | off_t offset) |
58 | off_t offset) |
| 51 | { |
59 | { |
| Line 258... | Line 266... | ||
| 258 | sf = uint16_t_le2host(bs->sec_per_fat); |
266 | sf = uint16_t_le2host(bs->sec_per_fat); |
| 259 | 267 | ||
| 260 | /* |
268 | /* |
| 261 | * Search FAT1 for unused clusters. |
269 | * Search FAT1 for unused clusters. |
| 262 | */ |
270 | */ |
| - | 271 | futex_down(&fat_alloc_lock); |
|
| 263 | for (b = 0, cl = 0; b < sf; blk++) { |
272 | for (b = 0, cl = 0; b < sf; blk++) { |
| 264 | blk = block_get(dev_handle, rscnt + b, bps); |
273 | blk = block_get(dev_handle, rscnt + b, bps); |
| 265 | for (c = 0; c < bps / sizeof(fat_cluster_t); c++, cl++) { |
274 | for (c = 0; c < bps / sizeof(fat_cluster_t); c++, cl++) { |
| 266 | fat_cluster_t *clst = (fat_cluster_t *)blk->data + c; |
275 | fat_cluster_t *clst = (fat_cluster_t *)blk->data + c; |
| 267 | if (uint16_t_le2host(*clst) == FAT_CLST_RES0) { |
276 | if (uint16_t_le2host(*clst) == FAT_CLST_RES0) { |
| Line 281... | Line 290... | ||
| 281 | fat_alloc_shadow_clusters(bs, |
290 | fat_alloc_shadow_clusters(bs, |
| 282 | dev_handle, lifo, nclsts); |
291 | dev_handle, lifo, nclsts); |
| 283 | *mcl = lifo[found - 1]; |
292 | *mcl = lifo[found - 1]; |
| 284 | *lcl = lifo[0]; |
293 | *lcl = lifo[0]; |
| 285 | free(lifo); |
294 | free(lifo); |
| - | 295 | futex_up(&fat_alloc_lock); |
|
| 286 | return EOK; |
296 | return EOK; |
| 287 | } |
297 | } |
| 288 | } |
298 | } |
| 289 | } |
299 | } |
| 290 | block_put(blk); |
300 | block_put(blk); |
| 291 | } |
301 | } |
| - | 302 | futex_up(&fat_alloc_lock); |
|
| 292 | 303 | ||
| 293 | /* |
304 | /* |
| 294 | * We could not find enough clusters. Now we need to free the clusters |
305 | * We could not find enough clusters. Now we need to free the clusters |
| 295 | * we have allocated so far. |
306 | * we have allocated so far. |
| 296 | */ |
307 | */ |