Changeset 6571b78 in mainline


Ignore:
Timestamp:
2008-11-22T11:04:00Z (16 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3ff2b54
Parents:
ce4a3dae
Message:

Implementation of fat_create_node().

Location:
uspace/srv/fs/fat
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/fat/fat.h

    rce4a3dae r6571b78  
    205205extern void fat_truncate(ipc_callid_t, ipc_call_t *);
    206206
     207extern fat_idx_t *fat_idx_get_new(dev_handle_t);
    207208extern fat_idx_t *fat_idx_get_by_pos(dev_handle_t, fat_cluster_t, unsigned);
    208209extern fat_idx_t *fat_idx_get_by_index(dev_handle_t, fs_index_t);
  • uspace/srv/fs/fat/fat_ops.c

    rce4a3dae r6571b78  
    235235{
    236236        fat_node_t *nodep = (fat_node_t *)node;
     237        bool destroy = false;
    237238
    238239        futex_down(&nodep->lock);
    239240        if (!--nodep->refcnt) {
    240                 futex_down(&ffn_futex);
    241                 list_append(&nodep->ffn_link, &ffn_head);
    242                 futex_up(&ffn_futex);
     241                if (nodep->idx) {
     242                        futex_down(&ffn_futex);
     243                        list_append(&nodep->ffn_link, &ffn_head);
     244                        futex_up(&ffn_futex);
     245                } else {
     246                        /*
     247                         * The node does not have any index structure associated
     248                         * with itself. This can only mean that we are releasing
     249                         * the node after a failed attempt to allocate the index
     250                         * structure for it.
     251                         */
     252                        destroy = true;
     253                }
    243254        }
    244255        futex_up(&nodep->lock);
    245 }
    246 
    247 static void *fat_create(dev_handle_t dev_handle, int flags)
    248 {
    249         return NULL;    /* not supported at the moment */
    250 }
    251 
    252 static int fat_destroy(void *node)
     256        if (destroy)
     257                free(node);
     258}
     259
     260static void *fat_create_node(dev_handle_t dev_handle, int flags)
     261{
     262        fat_idx_t *idxp;
     263        fat_node_t *nodep;
     264
     265        nodep = fat_node_get_new();
     266        if (!nodep)
     267                return NULL;
     268        idxp = fat_idx_get_new(dev_handle);
     269        if (!idxp) {
     270                fat_node_put(nodep);
     271                return NULL;
     272        }
     273        /* idxp->lock held */
     274        if (flags & L_DIRECTORY) {
     275                nodep->type = FAT_DIRECTORY;
     276        } else {
     277                nodep->type = FAT_FILE;
     278        }
     279        nodep->size = 0;
     280        nodep->firstc = FAT_CLST_RES0;
     281        nodep->lnkcnt = 0;      /* not linked anywhere */
     282        nodep->refcnt = 1;
     283
     284        nodep->idx = idxp;
     285        idxp->nodep = nodep;
     286
     287        futex_up(&idxp->lock);
     288        return nodep;
     289}
     290
     291static int fat_destroy_node(void *node)
    253292{
    254293        return ENOTSUP; /* not supported at the moment */
     
    425464        .node_get = fat_node_get,
    426465        .node_put = fat_node_put,
    427         .create = fat_create,
    428         .destroy = fat_destroy,
     466        .create = fat_create_node,
     467        .destroy = fat_destroy_node,
    429468        .link = fat_link,
    430469        .unlink = fat_unlink,
Note: See TracChangeset for help on using the changeset viewer.