Changeset 6ebe721 in mainline for uspace/srv/fs/fat/fat_ops.c
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.