Rev 4537 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4537 | Rev 4668 | ||
---|---|---|---|
Line 49... | Line 49... | ||
49 | #include <string.h> |
49 | #include <string.h> |
50 | #include <byteorder.h> |
50 | #include <byteorder.h> |
51 | #include <adt/hash_table.h> |
51 | #include <adt/hash_table.h> |
52 | #include <adt/list.h> |
52 | #include <adt/list.h> |
53 | #include <assert.h> |
53 | #include <assert.h> |
54 | #include <futex.h> |
54 | #include <fibril_sync.h> |
55 | #include <sys/mman.h> |
55 | #include <sys/mman.h> |
56 | #include <align.h> |
56 | #include <align.h> |
57 | 57 | ||
58 | #define FAT_NODE(node) ((node) ? (fat_node_t *) (node)->data : NULL) |
58 | #define FAT_NODE(node) ((node) ? (fat_node_t *) (node)->data : NULL) |
59 | #define FS_NODE(node) ((node) ? (node)->bp : NULL) |
59 | #define FS_NODE(node) ((node) ? (node)->bp : NULL) |
60 | 60 | ||
61 | /** Futex protecting the list of cached free FAT nodes. */ |
61 | /** Mutex protecting the list of cached free FAT nodes. */ |
62 | static futex_t ffn_futex = FUTEX_INITIALIZER; |
62 | static FIBRIL_MUTEX_INITIALIZE(ffn_mutex); |
63 | 63 | ||
64 | /** List of cached free FAT nodes. */ |
64 | /** List of cached free FAT nodes. */ |
65 | static LIST_INITIALIZE(ffn_head); |
65 | static LIST_INITIALIZE(ffn_head); |
66 | 66 | ||
67 | static void fat_node_initialize(fat_node_t *node) |
67 | static void fat_node_initialize(fat_node_t *node) |
68 | { |
68 | { |
69 | futex_initialize(&node->lock, 1); |
69 | fibril_mutex_initialize(&node->lock); |
70 | node->bp = NULL; |
70 | node->bp = NULL; |
71 | node->idx = NULL; |
71 | node->idx = NULL; |
72 | node->type = 0; |
72 | node->type = 0; |
73 | link_initialize(&node->ffn_link); |
73 | link_initialize(&node->ffn_link); |
74 | node->size = 0; |
74 | node->size = 0; |
Line 113... | Line 113... | ||
113 | static fat_node_t *fat_node_get_new(void) |
113 | static fat_node_t *fat_node_get_new(void) |
114 | { |
114 | { |
115 | fs_node_t *fn; |
115 | fs_node_t *fn; |
116 | fat_node_t *nodep; |
116 | fat_node_t *nodep; |
117 | 117 | ||
118 | futex_down(&ffn_futex); |
118 | fibril_mutex_lock(&ffn_mutex); |
119 | if (!list_empty(&ffn_head)) { |
119 | if (!list_empty(&ffn_head)) { |
120 | /* Try to use a cached free node structure. */ |
120 | /* Try to use a cached free node structure. */ |
121 | fat_idx_t *idxp_tmp; |
121 | fat_idx_t *idxp_tmp; |
122 | nodep = list_get_instance(ffn_head.next, fat_node_t, ffn_link); |
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 | goto skip_cache; |
124 | goto skip_cache; |
125 | idxp_tmp = nodep->idx; |
125 | idxp_tmp = nodep->idx; |
126 | if (futex_trydown(&idxp_tmp->lock) == ESYNCH_WOULD_BLOCK) { |
126 | if (!fibril_mutex_trylock(&idxp_tmp->lock)) { |
127 | futex_up(&nodep->lock); |
127 | fibril_mutex_unlock(&nodep->lock); |
128 | goto skip_cache; |
128 | goto skip_cache; |
129 | } |
129 | } |
130 | list_remove(&nodep->ffn_link); |
130 | list_remove(&nodep->ffn_link); |
131 | futex_up(&ffn_futex); |
131 | fibril_mutex_unlock(&ffn_mutex); |
132 | if (nodep->dirty) |
132 | if (nodep->dirty) |
133 | fat_node_sync(nodep); |
133 | fat_node_sync(nodep); |
134 | idxp_tmp->nodep = NULL; |
134 | idxp_tmp->nodep = NULL; |
135 | futex_up(&nodep->lock); |
135 | fibril_mutex_unlock(&nodep->lock); |
136 | futex_up(&idxp_tmp->lock); |
136 | fibril_mutex_unlock(&idxp_tmp->lock); |
137 | fn = FS_NODE(nodep); |
137 | fn = FS_NODE(nodep); |
138 | } else { |
138 | } else { |
139 | skip_cache: |
139 | skip_cache: |
140 | /* Try to allocate a new node structure. */ |
140 | /* Try to allocate a new node structure. */ |
141 | futex_up(&ffn_futex); |
141 | fibril_mutex_unlock(&ffn_mutex); |
142 | fn = (fs_node_t *)malloc(sizeof(fs_node_t)); |
142 | fn = (fs_node_t *)malloc(sizeof(fs_node_t)); |
143 | if (!fn) |
143 | if (!fn) |
144 | return NULL; |
144 | return NULL; |
145 | nodep = (fat_node_t *)malloc(sizeof(fat_node_t)); |
145 | nodep = (fat_node_t *)malloc(sizeof(fat_node_t)); |
146 | if (!nodep) { |
146 | if (!nodep) { |
Line 173... | Line 173... | ||
173 | if (idxp->nodep) { |
173 | if (idxp->nodep) { |
174 | /* |
174 | /* |
175 | * We are lucky. |
175 | * We are lucky. |
176 | * The node is already instantiated in memory. |
176 | * The node is already instantiated in memory. |
177 | */ |
177 | */ |
178 | futex_down(&idxp->nodep->lock); |
178 | fibril_mutex_lock(&idxp->nodep->lock); |
179 | if (!idxp->nodep->refcnt++) |
179 | if (!idxp->nodep->refcnt++) |
180 | list_remove(&idxp->nodep->ffn_link); |
180 | list_remove(&idxp->nodep->ffn_link); |
181 | futex_up(&idxp->nodep->lock); |
181 | fibril_mutex_unlock(&idxp->nodep->lock); |
182 | return idxp->nodep; |
182 | return idxp->nodep; |
183 | } |
183 | } |
184 | 184 | ||
185 | /* |
185 | /* |
186 | * We must instantiate the node from the file system. |
186 | * We must instantiate the node from the file system. |
Line 266... | Line 266... | ||
266 | idxp = fat_idx_get_by_index(dev_handle, index); |
266 | idxp = fat_idx_get_by_index(dev_handle, index); |
267 | if (!idxp) |
267 | if (!idxp) |
268 | return NULL; |
268 | return NULL; |
269 | /* idxp->lock held */ |
269 | /* idxp->lock held */ |
270 | nodep = fat_node_get_core(idxp); |
270 | nodep = fat_node_get_core(idxp); |
271 | futex_up(&idxp->lock); |
271 | fibril_mutex_unlock(&idxp->lock); |
272 | return FS_NODE(nodep); |
272 | return FS_NODE(nodep); |
273 | } |
273 | } |
274 | 274 | ||
275 | void fat_node_put(fs_node_t *fn) |
275 | void fat_node_put(fs_node_t *fn) |
276 | { |
276 | { |
277 | fat_node_t *nodep = FAT_NODE(fn); |
277 | fat_node_t *nodep = FAT_NODE(fn); |
278 | bool destroy = false; |
278 | bool destroy = false; |
279 | 279 | ||
280 | futex_down(&nodep->lock); |
280 | fibril_mutex_lock(&nodep->lock); |
281 | if (!--nodep->refcnt) { |
281 | if (!--nodep->refcnt) { |
282 | if (nodep->idx) { |
282 | if (nodep->idx) { |
283 | futex_down(&ffn_futex); |
283 | fibril_mutex_lock(&ffn_mutex); |
284 | list_append(&nodep->ffn_link, &ffn_head); |
284 | list_append(&nodep->ffn_link, &ffn_head); |
285 | futex_up(&ffn_futex); |
285 | fibril_mutex_unlock(&ffn_mutex); |
286 | } else { |
286 | } else { |
287 | /* |
287 | /* |
288 | * The node does not have any index structure associated |
288 | * The node does not have any index structure associated |
289 | * with itself. This can only mean that we are releasing |
289 | * with itself. This can only mean that we are releasing |
290 | * the node after a failed attempt to allocate the index |
290 | * the node after a failed attempt to allocate the index |
291 | * structure for it. |
291 | * structure for it. |
292 | */ |
292 | */ |
293 | destroy = true; |
293 | destroy = true; |
294 | } |
294 | } |
295 | } |
295 | } |
296 | futex_up(&nodep->lock); |
296 | fibril_mutex_unlock(&nodep->lock); |
297 | if (destroy) { |
297 | if (destroy) { |
298 | free(nodep->bp); |
298 | free(nodep->bp); |
299 | free(nodep); |
299 | free(nodep); |
300 | } |
300 | } |
301 | } |
301 | } |
Line 358... | Line 358... | ||
358 | nodep->dirty = true; |
358 | nodep->dirty = true; |
359 | 359 | ||
360 | nodep->idx = idxp; |
360 | nodep->idx = idxp; |
361 | idxp->nodep = nodep; |
361 | idxp->nodep = nodep; |
362 | 362 | ||
363 | futex_up(&idxp->lock); |
363 | fibril_mutex_unlock(&idxp->lock); |
364 | return FS_NODE(nodep); |
364 | return FS_NODE(nodep); |
365 | } |
365 | } |
366 | 366 | ||
367 | int fat_destroy_node(fs_node_t *fn) |
367 | int fat_destroy_node(fs_node_t *fn) |
368 | { |
368 | { |
Line 407... | Line 407... | ||
407 | unsigned dps; |
407 | unsigned dps; |
408 | unsigned blocks; |
408 | unsigned blocks; |
409 | fat_cluster_t mcl, lcl; |
409 | fat_cluster_t mcl, lcl; |
410 | int rc; |
410 | int rc; |
411 | 411 | ||
412 | futex_down(&childp->lock); |
412 | fibril_mutex_lock(&childp->lock); |
413 | if (childp->lnkcnt == 1) { |
413 | if (childp->lnkcnt == 1) { |
414 | /* |
414 | /* |
415 | * On FAT, we don't support multiple hard links. |
415 | * On FAT, we don't support multiple hard links. |
416 | */ |
416 | */ |
417 | futex_up(&childp->lock); |
417 | fibril_mutex_unlock(&childp->lock); |
418 | return EMLINK; |
418 | return EMLINK; |
419 | } |
419 | } |
420 | assert(childp->lnkcnt == 0); |
420 | assert(childp->lnkcnt == 0); |
421 | futex_up(&childp->lock); |
421 | fibril_mutex_unlock(&childp->lock); |
422 | 422 | ||
423 | if (!fat_dentry_name_verify(name)) { |
423 | if (!fat_dentry_name_verify(name)) { |
424 | /* |
424 | /* |
425 | * Attempt to create unsupported name. |
425 | * Attempt to create unsupported name. |
426 | */ |
426 | */ |
Line 430... | Line 430... | ||
430 | /* |
430 | /* |
431 | * Get us an unused parent node's dentry or grow the parent and allocate |
431 | * Get us an unused parent node's dentry or grow the parent and allocate |
432 | * a new one. |
432 | * a new one. |
433 | */ |
433 | */ |
434 | 434 | ||
435 | futex_down(&parentp->idx->lock); |
435 | fibril_mutex_lock(&parentp->idx->lock); |
436 | bs = block_bb_get(parentp->idx->dev_handle); |
436 | bs = block_bb_get(parentp->idx->dev_handle); |
437 | bps = uint16_t_le2host(bs->bps); |
437 | bps = uint16_t_le2host(bs->bps); |
438 | dps = bps / sizeof(fat_dentry_t); |
438 | dps = bps / sizeof(fat_dentry_t); |
439 | 439 | ||
440 | blocks = parentp->size / bps; |
440 | blocks = parentp->size / bps; |
Line 461... | Line 461... | ||
461 | /* |
461 | /* |
462 | * We need to grow the parent in order to create a new unused dentry. |
462 | * We need to grow the parent in order to create a new unused dentry. |
463 | */ |
463 | */ |
464 | if (parentp->idx->pfc == FAT_CLST_ROOT) { |
464 | if (parentp->idx->pfc == FAT_CLST_ROOT) { |
465 | /* Can't grow the root directory. */ |
465 | /* Can't grow the root directory. */ |
466 | futex_up(&parentp->idx->lock); |
466 | fibril_mutex_unlock(&parentp->idx->lock); |
467 | return ENOSPC; |
467 | return ENOSPC; |
468 | } |
468 | } |
469 | rc = fat_alloc_clusters(bs, parentp->idx->dev_handle, 1, &mcl, &lcl); |
469 | rc = fat_alloc_clusters(bs, parentp->idx->dev_handle, 1, &mcl, &lcl); |
470 | if (rc != EOK) { |
470 | if (rc != EOK) { |
471 | futex_up(&parentp->idx->lock); |
471 | fibril_mutex_unlock(&parentp->idx->lock); |
472 | return rc; |
472 | return rc; |
473 | } |
473 | } |
474 | fat_append_clusters(bs, parentp, mcl); |
474 | fat_append_clusters(bs, parentp, mcl); |
475 | b = fat_block_get(bs, parentp, i, BLOCK_FLAGS_NOREAD); |
475 | b = fat_block_get(bs, parentp, i, BLOCK_FLAGS_NOREAD); |
476 | d = (fat_dentry_t *)b->data; |
476 | d = (fat_dentry_t *)b->data; |
Line 489... | Line 489... | ||
489 | */ |
489 | */ |
490 | memset(d, 0, sizeof(fat_dentry_t)); |
490 | memset(d, 0, sizeof(fat_dentry_t)); |
491 | fat_dentry_name_set(d, name); |
491 | fat_dentry_name_set(d, name); |
492 | b->dirty = true; /* need to sync block */ |
492 | b->dirty = true; /* need to sync block */ |
493 | block_put(b); |
493 | block_put(b); |
494 | futex_up(&parentp->idx->lock); |
494 | fibril_mutex_unlock(&parentp->idx->lock); |
495 | 495 | ||
496 | futex_down(&childp->idx->lock); |
496 | fibril_mutex_lock(&childp->idx->lock); |
497 | 497 | ||
498 | /* |
498 | /* |
499 | * If possible, create the Sub-directory Identifier Entry and the |
499 | * If possible, create the Sub-directory Identifier Entry and the |
500 | * Sub-directory Parent Pointer Entry (i.e. "." and ".."). These entries |
500 | * Sub-directory Parent Pointer Entry (i.e. "." and ".."). These entries |
501 | * are not mandatory according to Standard ECMA-107 and HelenOS VFS does |
501 | * are not mandatory according to Standard ECMA-107 and HelenOS VFS does |
Line 527... | Line 527... | ||
527 | b->dirty = true; /* need to sync block */ |
527 | b->dirty = true; /* need to sync block */ |
528 | block_put(b); |
528 | block_put(b); |
529 | 529 | ||
530 | childp->idx->pfc = parentp->firstc; |
530 | childp->idx->pfc = parentp->firstc; |
531 | childp->idx->pdi = i * dps + j; |
531 | childp->idx->pdi = i * dps + j; |
532 | futex_up(&childp->idx->lock); |
532 | fibril_mutex_unlock(&childp->idx->lock); |
533 | 533 | ||
534 | futex_down(&childp->lock); |
534 | fibril_mutex_lock(&childp->lock); |
535 | childp->lnkcnt = 1; |
535 | childp->lnkcnt = 1; |
536 | childp->dirty = true; /* need to sync node */ |
536 | childp->dirty = true; /* need to sync node */ |
537 | futex_up(&childp->lock); |
537 | fibril_mutex_unlock(&childp->lock); |
538 | 538 | ||
539 | /* |
539 | /* |
540 | * Hash in the index structure into the position hash. |
540 | * Hash in the index structure into the position hash. |
541 | */ |
541 | */ |
542 | fat_idx_hashin(childp->idx); |
542 | fat_idx_hashin(childp->idx); |
Line 557... | Line 557... | ||
557 | return EBUSY; |
557 | return EBUSY; |
558 | 558 | ||
559 | if (fat_has_children(cfn)) |
559 | if (fat_has_children(cfn)) |
560 | return ENOTEMPTY; |
560 | return ENOTEMPTY; |
561 | 561 | ||
562 | futex_down(&parentp->lock); |
562 | fibril_mutex_lock(&parentp->lock); |
563 | futex_down(&childp->lock); |
563 | fibril_mutex_lock(&childp->lock); |
564 | assert(childp->lnkcnt == 1); |
564 | assert(childp->lnkcnt == 1); |
565 | futex_down(&childp->idx->lock); |
565 | fibril_mutex_lock(&childp->idx->lock); |
566 | bs = block_bb_get(childp->idx->dev_handle); |
566 | bs = block_bb_get(childp->idx->dev_handle); |
567 | bps = uint16_t_le2host(bs->bps); |
567 | bps = uint16_t_le2host(bs->bps); |
568 | 568 | ||
569 | b = _fat_block_get(bs, childp->idx->dev_handle, childp->idx->pfc, |
569 | b = _fat_block_get(bs, childp->idx->dev_handle, childp->idx->pfc, |
570 | (childp->idx->pdi * sizeof(fat_dentry_t)) / bps, |
570 | (childp->idx->pdi * sizeof(fat_dentry_t)) / bps, |
Line 579... | Line 579... | ||
579 | /* remove the index structure from the position hash */ |
579 | /* remove the index structure from the position hash */ |
580 | fat_idx_hashout(childp->idx); |
580 | fat_idx_hashout(childp->idx); |
581 | /* clear position information */ |
581 | /* clear position information */ |
582 | childp->idx->pfc = FAT_CLST_RES0; |
582 | childp->idx->pfc = FAT_CLST_RES0; |
583 | childp->idx->pdi = 0; |
583 | childp->idx->pdi = 0; |
584 | futex_up(&childp->idx->lock); |
584 | fibril_mutex_unlock(&childp->idx->lock); |
585 | childp->lnkcnt = 0; |
585 | childp->lnkcnt = 0; |
586 | childp->dirty = true; |
586 | childp->dirty = true; |
587 | futex_up(&childp->lock); |
587 | fibril_mutex_unlock(&childp->lock); |
588 | futex_up(&parentp->lock); |
588 | fibril_mutex_unlock(&parentp->lock); |
589 | 589 | ||
590 | return EOK; |
590 | return EOK; |
591 | } |
591 | } |
592 | 592 | ||
593 | fs_node_t *fat_match(fs_node_t *pfn, const char *component) |
593 | fs_node_t *fat_match(fs_node_t *pfn, const char *component) |
Line 600... | Line 600... | ||
600 | unsigned dps; /* dentries per sector */ |
600 | unsigned dps; /* dentries per sector */ |
601 | unsigned blocks; |
601 | unsigned blocks; |
602 | fat_dentry_t *d; |
602 | fat_dentry_t *d; |
603 | block_t *b; |
603 | block_t *b; |
604 | 604 | ||
605 | futex_down(&parentp->idx->lock); |
605 | fibril_mutex_lock(&parentp->idx->lock); |
606 | bs = block_bb_get(parentp->idx->dev_handle); |
606 | bs = block_bb_get(parentp->idx->dev_handle); |
607 | bps = uint16_t_le2host(bs->bps); |
607 | bps = uint16_t_le2host(bs->bps); |
608 | dps = bps / sizeof(fat_dentry_t); |
608 | dps = bps / sizeof(fat_dentry_t); |
609 | blocks = parentp->size / bps; |
609 | blocks = parentp->size / bps; |
610 | for (i = 0; i < blocks; i++) { |
610 | for (i = 0; i < blocks; i++) { |
Line 615... | Line 615... | ||
615 | case FAT_DENTRY_SKIP: |
615 | case FAT_DENTRY_SKIP: |
616 | case FAT_DENTRY_FREE: |
616 | case FAT_DENTRY_FREE: |
617 | continue; |
617 | continue; |
618 | case FAT_DENTRY_LAST: |
618 | case FAT_DENTRY_LAST: |
619 | block_put(b); |
619 | block_put(b); |
620 | futex_up(&parentp->idx->lock); |
620 | fibril_mutex_unlock(&parentp->idx->lock); |
621 | return NULL; |
621 | return NULL; |
622 | default: |
622 | default: |
623 | case FAT_DENTRY_VALID: |
623 | case FAT_DENTRY_VALID: |
624 | fat_dentry_name_get(d, name); |
624 | fat_dentry_name_get(d, name); |
625 | break; |
625 | break; |
Line 634... | Line 634... | ||
634 | * order. |
634 | * order. |
635 | */ |
635 | */ |
636 | fat_idx_t *idx = fat_idx_get_by_pos( |
636 | fat_idx_t *idx = fat_idx_get_by_pos( |
637 | parentp->idx->dev_handle, parentp->firstc, |
637 | parentp->idx->dev_handle, parentp->firstc, |
638 | i * dps + j); |
638 | i * dps + j); |
639 | futex_up(&parentp->idx->lock); |
639 | fibril_mutex_unlock(&parentp->idx->lock); |
640 | if (!idx) { |
640 | if (!idx) { |
641 | /* |
641 | /* |
642 | * Can happen if memory is low or if we |
642 | * Can happen if memory is low or if we |
643 | * run out of 32-bit indices. |
643 | * run out of 32-bit indices. |
644 | */ |
644 | */ |
645 | block_put(b); |
645 | block_put(b); |
646 | return NULL; |
646 | return NULL; |
647 | } |
647 | } |
648 | nodep = fat_node_get_core(idx); |
648 | nodep = fat_node_get_core(idx); |
649 | futex_up(&idx->lock); |
649 | fibril_mutex_unlock(&idx->lock); |
650 | block_put(b); |
650 | block_put(b); |
651 | return FS_NODE(nodep); |
651 | return FS_NODE(nodep); |
652 | } |
652 | } |
653 | } |
653 | } |
654 | block_put(b); |
654 | block_put(b); |
655 | } |
655 | } |
656 | 656 | ||
657 | futex_up(&parentp->idx->lock); |
657 | fibril_mutex_unlock(&parentp->idx->lock); |
658 | return NULL; |
658 | return NULL; |
659 | } |
659 | } |
660 | 660 | ||
661 | fs_index_t fat_index_get(fs_node_t *fn) |
661 | fs_index_t fat_index_get(fs_node_t *fn) |
662 | { |
662 | { |
Line 684... | Line 684... | ||
684 | unsigned i, j; |
684 | unsigned i, j; |
685 | 685 | ||
686 | if (nodep->type != FAT_DIRECTORY) |
686 | if (nodep->type != FAT_DIRECTORY) |
687 | return false; |
687 | return false; |
688 | 688 | ||
689 | futex_down(&nodep->idx->lock); |
689 | fibril_mutex_lock(&nodep->idx->lock); |
690 | bs = block_bb_get(nodep->idx->dev_handle); |
690 | bs = block_bb_get(nodep->idx->dev_handle); |
691 | bps = uint16_t_le2host(bs->bps); |
691 | bps = uint16_t_le2host(bs->bps); |
692 | dps = bps / sizeof(fat_dentry_t); |
692 | dps = bps / sizeof(fat_dentry_t); |
693 | 693 | ||
694 | blocks = nodep->size / bps; |
694 | blocks = nodep->size / bps; |
Line 703... | Line 703... | ||
703 | case FAT_DENTRY_SKIP: |
703 | case FAT_DENTRY_SKIP: |
704 | case FAT_DENTRY_FREE: |
704 | case FAT_DENTRY_FREE: |
705 | continue; |
705 | continue; |
706 | case FAT_DENTRY_LAST: |
706 | case FAT_DENTRY_LAST: |
707 | block_put(b); |
707 | block_put(b); |
708 | futex_up(&nodep->idx->lock); |
708 | fibril_mutex_unlock(&nodep->idx->lock); |
709 | return false; |
709 | return false; |
710 | default: |
710 | default: |
711 | case FAT_DENTRY_VALID: |
711 | case FAT_DENTRY_VALID: |
712 | block_put(b); |
712 | block_put(b); |
713 | futex_up(&nodep->idx->lock); |
713 | fibril_mutex_unlock(&nodep->idx->lock); |
714 | return true; |
714 | return true; |
715 | } |
715 | } |
716 | block_put(b); |
716 | block_put(b); |
717 | futex_up(&nodep->idx->lock); |
717 | fibril_mutex_unlock(&nodep->idx->lock); |
718 | return true; |
718 | return true; |
719 | } |
719 | } |
720 | block_put(b); |
720 | block_put(b); |
721 | } |
721 | } |
722 | 722 | ||
723 | futex_up(&nodep->idx->lock); |
723 | fibril_mutex_unlock(&nodep->idx->lock); |
724 | return false; |
724 | return false; |
725 | } |
725 | } |
726 | 726 | ||
727 | fs_node_t *fat_root_get(dev_handle_t dev_handle) |
727 | fs_node_t *fat_root_get(dev_handle_t dev_handle) |
728 | { |
728 | { |
Line 768... | Line 768... | ||
768 | */ |
768 | */ |
769 | 769 | ||
770 | void fat_mounted(ipc_callid_t rid, ipc_call_t *request) |
770 | void fat_mounted(ipc_callid_t rid, ipc_call_t *request) |
771 | { |
771 | { |
772 | dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); |
772 | dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); |
- | 773 | enum cache_mode cmode; |
|
773 | fat_bs_t *bs; |
774 | fat_bs_t *bs; |
774 | uint16_t bps; |
775 | uint16_t bps; |
775 | uint16_t rde; |
776 | uint16_t rde; |
776 | int rc; |
777 | int rc; |
777 | 778 | ||
Line 795... | Line 796... | ||
795 | free(opts); |
796 | free(opts); |
796 | return; |
797 | return; |
797 | } |
798 | } |
798 | opts[size] = '\0'; |
799 | opts[size] = '\0'; |
799 | 800 | ||
- | 801 | /* Check for option enabling write through. */ |
|
- | 802 | if (str_cmp(opts, "wtcache") == 0) |
|
- | 803 | cmode = CACHE_MODE_WT; |
|
- | 804 | else |
|
- | 805 | cmode = CACHE_MODE_WB; |
|
- | 806 | ||
800 | /* initialize libblock */ |
807 | /* initialize libblock */ |
801 | rc = block_init(dev_handle, BS_SIZE); |
808 | rc = block_init(dev_handle, BS_SIZE); |
802 | if (rc != EOK) { |
809 | if (rc != EOK) { |
803 | ipc_answer_0(rid, rc); |
810 | ipc_answer_0(rid, rc); |
804 | return; |
811 | return; |
Line 824... | Line 831... | ||
824 | ipc_answer_0(rid, ENOTSUP); |
831 | ipc_answer_0(rid, ENOTSUP); |
825 | return; |
832 | return; |
826 | } |
833 | } |
827 | 834 | ||
828 | /* Initialize the block cache */ |
835 | /* Initialize the block cache */ |
829 | rc = block_cache_init(dev_handle, bps, 0 /* XXX */); |
836 | rc = block_cache_init(dev_handle, bps, 0 /* XXX */, cmode); |
830 | if (rc != EOK) { |
837 | if (rc != EOK) { |
831 | block_fini(dev_handle); |
838 | block_fini(dev_handle); |
832 | ipc_answer_0(rid, rc); |
839 | ipc_answer_0(rid, rc); |
833 | return; |
840 | return; |
834 | } |
841 | } |
Line 879... | Line 886... | ||
879 | rootp->idx = ridxp; |
886 | rootp->idx = ridxp; |
880 | ridxp->nodep = rootp; |
887 | ridxp->nodep = rootp; |
881 | rootp->bp = rfn; |
888 | rootp->bp = rfn; |
882 | rfn->data = rootp; |
889 | rfn->data = rootp; |
883 | 890 | ||
884 | futex_up(&ridxp->lock); |
891 | fibril_mutex_unlock(&ridxp->lock); |
885 | 892 | ||
886 | ipc_answer_3(rid, EOK, ridxp->index, rootp->size, rootp->lnkcnt); |
893 | ipc_answer_3(rid, EOK, ridxp->index, rootp->size, rootp->lnkcnt); |
887 | } |
894 | } |
888 | 895 | ||
889 | void fat_mount(ipc_callid_t rid, ipc_call_t *request) |
896 | void fat_mount(ipc_callid_t rid, ipc_call_t *request) |
Line 1193... | Line 1200... | ||
1193 | void fat_open_node(ipc_callid_t rid, ipc_call_t *request) |
1200 | void fat_open_node(ipc_callid_t rid, ipc_call_t *request) |
1194 | { |
1201 | { |
1195 | libfs_open_node(&fat_libfs_ops, fat_reg.fs_handle, rid, request); |
1202 | libfs_open_node(&fat_libfs_ops, fat_reg.fs_handle, rid, request); |
1196 | } |
1203 | } |
1197 | 1204 | ||
1198 | void fat_device(ipc_callid_t rid, ipc_call_t *request) |
1205 | void fat_stat(ipc_callid_t rid, ipc_call_t *request) |
1199 | { |
1206 | { |
1200 | ipc_answer_0(rid, ENOTSUP); |
1207 | libfs_stat(&fat_libfs_ops, fat_reg.fs_handle, rid, request); |
1201 | } |
1208 | } |
1202 | 1209 | ||
1203 | void fat_sync(ipc_callid_t rid, ipc_call_t *request) |
1210 | void fat_sync(ipc_callid_t rid, ipc_call_t *request) |
1204 | { |
1211 | { |
1205 | /* Dummy implementation */ |
1212 | /* Dummy implementation */ |