Changeset 6ebe721 in mainline
- Timestamp:
- 2009-06-17T22:07:42Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4e1b57d
- Parents:
- 34ca870
- Location:
- uspace/srv/fs/fat
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat.h
r34ca870 r6ebe721 36 36 #include "fat_fat.h" 37 37 #include <ipc/ipc.h> 38 #include <fibril_sync.h> 38 39 #include <libfs.h> 39 40 #include <atomic.h> … … 161 162 link_t uih_link; 162 163 163 f utex_tlock;164 fibril_mutex_t lock; 164 165 dev_handle_t dev_handle; 165 166 fs_index_t index; … … 182 183 fs_node_t *bp; 183 184 184 f utex_tlock;185 fibril_mutex_t lock; 185 186 fat_node_type_t type; 186 187 fat_idx_t *idx; -
uspace/srv/fs/fat/fat_fat.c
r34ca870 r6ebe721 46 46 #include <align.h> 47 47 #include <assert.h> 48 #include <f utex.h>48 #include <fibril_sync.h> 49 49 #include <mem.h> 50 50 51 51 /** 52 * The fat_alloc_lock futex protects all copies of the File Allocation Table52 * The fat_alloc_lock mutex protects all copies of the File Allocation Table 53 53 * during allocation of clusters. The lock does not have to be held durring 54 54 * deallocation of clusters. 55 55 */ 56 static futex_t fat_alloc_lock = FUTEX_INITIALIZER;56 static FIBRIL_MUTEX_INITIALIZE(fat_alloc_lock); 57 57 58 58 /** Walk the cluster chain. … … 327 327 * Search FAT1 for unused clusters. 328 328 */ 329 f utex_down(&fat_alloc_lock);329 fibril_mutex_lock(&fat_alloc_lock); 330 330 for (b = 0, cl = 0; b < sf; b++) { 331 331 blk = block_get(dev_handle, rscnt + b, BLOCK_FLAGS_NONE); … … 351 351 *lcl = lifo[0]; 352 352 free(lifo); 353 f utex_up(&fat_alloc_lock);353 fibril_mutex_unlock(&fat_alloc_lock); 354 354 return EOK; 355 355 } … … 358 358 block_put(blk); 359 359 } 360 f utex_up(&fat_alloc_lock);360 fibril_mutex_unlock(&fat_alloc_lock); 361 361 362 362 /* -
uspace/srv/fs/fat/fat_idx.c
r34ca870 r6ebe721 43 43 #include <adt/list.h> 44 44 #include <assert.h> 45 #include <f utex.h>45 #include <fibril_sync.h> 46 46 47 47 /** Each instance of this type describes one interval of freed VFS indices. */ … … 69 69 } unused_t; 70 70 71 /** Futex protecting the list of unused structures. */72 static futex_t unused_futex = FUTEX_INITIALIZER;71 /** Mutex protecting the list of unused structures. */ 72 static FIBRIL_MUTEX_INITIALIZE(unused_lock); 73 73 74 74 /** List of unused structures. */ … … 90 90 91 91 if (lock) 92 f utex_down(&unused_futex);92 fibril_mutex_lock(&unused_lock); 93 93 for (l = unused_head.next; l != &unused_head; l = l->next) { 94 94 u = list_get_instance(l, unused_t, link); … … 97 97 } 98 98 if (lock) 99 f utex_up(&unused_futex);99 fibril_mutex_unlock(&unused_lock); 100 100 return NULL; 101 101 } 102 102 103 /** Futex protecting the up_hash and ui_hash. */104 static futex_t used_futex = FUTEX_INITIALIZER;103 /** Mutex protecting the up_hash and ui_hash. */ 104 static FIBRIL_MUTEX_INITIALIZE(used_lock); 105 105 106 106 /** … … 232 232 *index = u->next++; 233 233 --u->remaining; 234 f utex_up(&unused_futex);234 fibril_mutex_unlock(&unused_lock); 235 235 return true; 236 236 } … … 245 245 free(f); 246 246 } 247 f utex_up(&unused_futex);247 fibril_mutex_unlock(&unused_lock); 248 248 return true; 249 249 } … … 253 253 * too many zero-sized nodes). 254 254 */ 255 f utex_up(&unused_futex);255 fibril_mutex_unlock(&unused_lock); 256 256 return false; 257 257 } … … 303 303 try_coalesce_intervals(lnk->prev, lnk, 304 304 lnk); 305 f utex_up(&unused_futex);305 fibril_mutex_unlock(&unused_lock); 306 306 return; 307 307 } … … 311 311 try_coalesce_intervals(lnk, lnk->next, 312 312 lnk); 313 f utex_up(&unused_futex);313 fibril_mutex_unlock(&unused_lock); 314 314 return; 315 315 } … … 322 322 n->last = index; 323 323 list_insert_before(&n->link, lnk); 324 f utex_up(&unused_futex);324 fibril_mutex_unlock(&unused_lock); 325 325 return; 326 326 } … … 336 336 list_append(&n->link, &u->freed_head); 337 337 } 338 f utex_up(&unused_futex);338 fibril_mutex_unlock(&unused_lock); 339 339 } 340 340 … … 353 353 link_initialize(&fidx->uph_link); 354 354 link_initialize(&fidx->uih_link); 355 f utex_initialize(&fidx->lock, 1);355 fibril_mutex_initialize(&fidx->lock); 356 356 fidx->dev_handle = dev_handle; 357 357 fidx->pfc = FAT_CLST_RES0; /* no parent yet */ … … 366 366 fat_idx_t *fidx; 367 367 368 f utex_down(&used_futex);368 fibril_mutex_lock(&used_lock); 369 369 fidx = fat_idx_create(dev_handle); 370 370 if (!fidx) { 371 f utex_up(&used_futex);371 fibril_mutex_unlock(&used_lock); 372 372 return NULL; 373 373 } … … 379 379 380 380 hash_table_insert(&ui_hash, ikey, &fidx->uih_link); 381 f utex_down(&fidx->lock);382 f utex_up(&used_futex);381 fibril_mutex_lock(&fidx->lock); 382 fibril_mutex_unlock(&used_lock); 383 383 384 384 return fidx; … … 396 396 }; 397 397 398 f utex_down(&used_futex);398 fibril_mutex_lock(&used_lock); 399 399 l = hash_table_find(&up_hash, pkey); 400 400 if (l) { … … 403 403 fidx = fat_idx_create(dev_handle); 404 404 if (!fidx) { 405 f utex_up(&used_futex);405 fibril_mutex_unlock(&used_lock); 406 406 return NULL; 407 407 } … … 418 418 hash_table_insert(&ui_hash, ikey, &fidx->uih_link); 419 419 } 420 f utex_down(&fidx->lock);421 f utex_up(&used_futex);420 fibril_mutex_lock(&fidx->lock); 421 fibril_mutex_unlock(&used_lock); 422 422 423 423 return fidx; … … 432 432 }; 433 433 434 f utex_down(&used_futex);434 fibril_mutex_lock(&used_lock); 435 435 hash_table_insert(&up_hash, pkey, &idx->uph_link); 436 f utex_up(&used_futex);436 fibril_mutex_unlock(&used_lock); 437 437 } 438 438 … … 445 445 }; 446 446 447 f utex_down(&used_futex);447 fibril_mutex_lock(&used_lock); 448 448 hash_table_remove(&up_hash, pkey, 3); 449 f utex_up(&used_futex);449 fibril_mutex_unlock(&used_lock); 450 450 } 451 451 … … 460 460 }; 461 461 462 f utex_down(&used_futex);462 fibril_mutex_lock(&used_lock); 463 463 l = hash_table_find(&ui_hash, ikey); 464 464 if (l) { … … 466 466 futex_down(&fidx->lock); 467 467 } 468 f utex_up(&used_futex);468 fibril_mutex_unlock(&used_lock); 469 469 470 470 return fidx; … … 484 484 assert(idx->pfc == FAT_CLST_RES0); 485 485 486 f utex_down(&used_futex);486 fibril_mutex_lock(&used_lock); 487 487 /* 488 488 * Since we can only free unlinked nodes, the index structure is not … … 491 491 */ 492 492 hash_table_remove(&ui_hash, ikey, 2); 493 f utex_up(&used_futex);493 fibril_mutex_unlock(&used_lock); 494 494 /* Release the VFS index. */ 495 495 fat_index_free(idx->dev_handle, idx->index); … … 525 525 return ENOMEM; 526 526 unused_initialize(u, dev_handle); 527 f utex_down(&unused_futex);527 fibril_mutex_lock(&unused_lock); 528 528 if (!unused_find(dev_handle, false)) 529 529 list_append(&u->link, &unused_head); 530 530 else 531 531 rc = EEXIST; 532 f utex_up(&unused_futex);532 fibril_mutex_unlock(&unused_lock); 533 533 return rc; 534 534 } … … 541 541 assert(u); 542 542 list_remove(&u->link); 543 f utex_up(&unused_futex);543 fibril_mutex_unlock(&unused_lock); 544 544 545 545 while (!list_empty(&u->freed_head)) { -
uspace/srv/fs/fat/fat_ops.c
r34ca870 r6ebe721 52 52 #include <adt/list.h> 53 53 #include <assert.h> 54 #include <f utex.h>54 #include <fibril_sync.h> 55 55 #include <sys/mman.h> 56 56 #include <align.h> … … 59 59 #define FS_NODE(node) ((node) ? (node)->bp : NULL) 60 60 61 /** Futex protecting the list of cached free FAT nodes. */62 static futex_t ffn_futex = FUTEX_INITIALIZER;61 /** Mutex protecting the list of cached free FAT nodes. */ 62 static FIBRIL_MUTEX_INITIALIZE(ffn_mutex); 63 63 64 64 /** List of cached free FAT nodes. */ … … 67 67 static void fat_node_initialize(fat_node_t *node) 68 68 { 69 f utex_initialize(&node->lock, 1);69 fibril_mutex_initialize(&node->lock); 70 70 node->bp = NULL; 71 71 node->idx = NULL; … … 116 116 fat_node_t *nodep; 117 117 118 f utex_down(&ffn_futex);118 fibril_mutex_lock(&ffn_mutex); 119 119 if (!list_empty(&ffn_head)) { 120 120 /* Try to use a cached free node structure. */ 121 121 fat_idx_t *idxp_tmp; 122 122 nodep = list_get_instance(ffn_head.next, fat_node_t, ffn_link); 123 if ( futex_trydown(&nodep->lock) == ESYNCH_WOULD_BLOCK)123 if (!fibril_mutex_trylock(&nodep->lock)) 124 124 goto skip_cache; 125 125 idxp_tmp = nodep->idx; 126 if ( futex_trydown(&idxp_tmp->lock) == ESYNCH_WOULD_BLOCK) {127 f utex_up(&nodep->lock);126 if (!fibril_mutex_trylock(&idxp_tmp->lock)) { 127 fibril_mutex_unlock(&nodep->lock); 128 128 goto skip_cache; 129 129 } 130 130 list_remove(&nodep->ffn_link); 131 f utex_up(&ffn_futex);131 fibril_mutex_unlock(&ffn_mutex); 132 132 if (nodep->dirty) 133 133 fat_node_sync(nodep); 134 134 idxp_tmp->nodep = NULL; 135 f utex_up(&nodep->lock);136 f utex_up(&idxp_tmp->lock);135 fibril_mutex_unlock(&nodep->lock); 136 fibril_mutex_unlock(&idxp_tmp->lock); 137 137 fn = FS_NODE(nodep); 138 138 } else { 139 139 skip_cache: 140 140 /* Try to allocate a new node structure. */ 141 f utex_up(&ffn_futex);141 fibril_mutex_unlock(&ffn_mutex); 142 142 fn = (fs_node_t *)malloc(sizeof(fs_node_t)); 143 143 if (!fn) … … 176 176 * The node is already instantiated in memory. 177 177 */ 178 f utex_down(&idxp->nodep->lock);178 fibril_mutex_lock(&idxp->nodep->lock); 179 179 if (!idxp->nodep->refcnt++) 180 180 list_remove(&idxp->nodep->ffn_link); 181 f utex_up(&idxp->nodep->lock);181 fibril_mutex_unlock(&idxp->nodep->lock); 182 182 return idxp->nodep; 183 183 } … … 269 269 /* idxp->lock held */ 270 270 nodep = fat_node_get_core(idxp); 271 f utex_up(&idxp->lock);271 fibril_mutex_unlock(&idxp->lock); 272 272 return FS_NODE(nodep); 273 273 } … … 278 278 bool destroy = false; 279 279 280 f utex_down(&nodep->lock);280 fibril_mutex_lock(&nodep->lock); 281 281 if (!--nodep->refcnt) { 282 282 if (nodep->idx) { 283 f utex_down(&ffn_futex);283 fibril_mutex_lock(&ffn_mutex); 284 284 list_append(&nodep->ffn_link, &ffn_head); 285 f utex_up(&ffn_futex);285 fibril_mutex_unlock(&ffn_mutex); 286 286 } else { 287 287 /* … … 294 294 } 295 295 } 296 f utex_up(&nodep->lock);296 fibril_mutex_unlock(&nodep->lock); 297 297 if (destroy) { 298 298 free(nodep->bp); … … 361 361 idxp->nodep = nodep; 362 362 363 f utex_up(&idxp->lock);363 fibril_mutex_unlock(&idxp->lock); 364 364 return FS_NODE(nodep); 365 365 } … … 410 410 int rc; 411 411 412 f utex_down(&childp->lock);412 fibril_mutex_lock(&childp->lock); 413 413 if (childp->lnkcnt == 1) { 414 414 /* 415 415 * On FAT, we don't support multiple hard links. 416 416 */ 417 f utex_up(&childp->lock);417 fibril_mutex_unlock(&childp->lock); 418 418 return EMLINK; 419 419 } 420 420 assert(childp->lnkcnt == 0); 421 f utex_up(&childp->lock);421 fibril_mutex_unlock(&childp->lock); 422 422 423 423 if (!fat_dentry_name_verify(name)) { … … 433 433 */ 434 434 435 f utex_down(&parentp->idx->lock);435 fibril_mutex_lock(&parentp->idx->lock); 436 436 bs = block_bb_get(parentp->idx->dev_handle); 437 437 bps = uint16_t_le2host(bs->bps); … … 464 464 if (parentp->idx->pfc == FAT_CLST_ROOT) { 465 465 /* Can't grow the root directory. */ 466 f utex_up(&parentp->idx->lock);466 fibril_mutex_unlock(&parentp->idx->lock); 467 467 return ENOSPC; 468 468 } 469 469 rc = fat_alloc_clusters(bs, parentp->idx->dev_handle, 1, &mcl, &lcl); 470 470 if (rc != EOK) { 471 f utex_up(&parentp->idx->lock);471 fibril_mutex_unlock(&parentp->idx->lock); 472 472 return rc; 473 473 } … … 492 492 b->dirty = true; /* need to sync block */ 493 493 block_put(b); 494 f utex_up(&parentp->idx->lock);495 496 f utex_down(&childp->idx->lock);494 fibril_mutex_unlock(&parentp->idx->lock); 495 496 fibril_mutex_lock(&childp->idx->lock); 497 497 498 498 /* … … 530 530 childp->idx->pfc = parentp->firstc; 531 531 childp->idx->pdi = i * dps + j; 532 f utex_up(&childp->idx->lock);533 534 f utex_down(&childp->lock);532 fibril_mutex_unlock(&childp->idx->lock); 533 534 fibril_mutex_lock(&childp->lock); 535 535 childp->lnkcnt = 1; 536 536 childp->dirty = true; /* need to sync node */ 537 f utex_up(&childp->lock);537 fibril_mutex_unlock(&childp->lock); 538 538 539 539 /* … … 560 560 return ENOTEMPTY; 561 561 562 f utex_down(&parentp->lock);563 f utex_down(&childp->lock);562 fibril_mutex_lock(&parentp->lock); 563 fibril_mutex_lock(&childp->lock); 564 564 assert(childp->lnkcnt == 1); 565 f utex_down(&childp->idx->lock);565 fibril_mutex_lock(&childp->idx->lock); 566 566 bs = block_bb_get(childp->idx->dev_handle); 567 567 bps = uint16_t_le2host(bs->bps); … … 582 582 childp->idx->pfc = FAT_CLST_RES0; 583 583 childp->idx->pdi = 0; 584 f utex_up(&childp->idx->lock);584 fibril_mutex_unlock(&childp->idx->lock); 585 585 childp->lnkcnt = 0; 586 586 childp->dirty = true; 587 f utex_up(&childp->lock);588 f utex_up(&parentp->lock);587 fibril_mutex_unlock(&childp->lock); 588 fibril_mutex_unlock(&parentp->lock); 589 589 590 590 return EOK; … … 603 603 block_t *b; 604 604 605 f utex_down(&parentp->idx->lock);605 fibril_mutex_lock(&parentp->idx->lock); 606 606 bs = block_bb_get(parentp->idx->dev_handle); 607 607 bps = uint16_t_le2host(bs->bps); … … 618 618 case FAT_DENTRY_LAST: 619 619 block_put(b); 620 f utex_up(&parentp->idx->lock);620 fibril_mutex_unlock(&parentp->idx->lock); 621 621 return NULL; 622 622 default: … … 637 637 parentp->idx->dev_handle, parentp->firstc, 638 638 i * dps + j); 639 f utex_up(&parentp->idx->lock);639 fibril_mutex_unlock(&parentp->idx->lock); 640 640 if (!idx) { 641 641 /* … … 647 647 } 648 648 nodep = fat_node_get_core(idx); 649 f utex_up(&idx->lock);649 fibril_mutex_unlock(&idx->lock); 650 650 block_put(b); 651 651 return FS_NODE(nodep); … … 655 655 } 656 656 657 f utex_up(&parentp->idx->lock);657 fibril_mutex_unlock(&parentp->idx->lock); 658 658 return NULL; 659 659 } … … 687 687 return false; 688 688 689 f utex_down(&nodep->idx->lock);689 fibril_mutex_lock(&nodep->idx->lock); 690 690 bs = block_bb_get(nodep->idx->dev_handle); 691 691 bps = uint16_t_le2host(bs->bps); … … 706 706 case FAT_DENTRY_LAST: 707 707 block_put(b); 708 f utex_up(&nodep->idx->lock);708 fibril_mutex_unlock(&nodep->idx->lock); 709 709 return false; 710 710 default: 711 711 case FAT_DENTRY_VALID: 712 712 block_put(b); 713 f utex_up(&nodep->idx->lock);713 fibril_mutex_unlock(&nodep->idx->lock); 714 714 return true; 715 715 } 716 716 block_put(b); 717 f utex_up(&nodep->idx->lock);717 fibril_mutex_unlock(&nodep->idx->lock); 718 718 return true; 719 719 } … … 721 721 } 722 722 723 f utex_up(&nodep->idx->lock);723 fibril_mutex_unlock(&nodep->idx->lock); 724 724 return false; 725 725 } … … 882 882 rfn->data = rootp; 883 883 884 f utex_up(&ridxp->lock);884 fibril_mutex_unlock(&ridxp->lock); 885 885 886 886 ipc_answer_3(rid, EOK, ridxp->index, rootp->size, rootp->lnkcnt);
Note:
See TracChangeset
for help on using the changeset viewer.