Subversion Repositories HelenOS

Rev

Rev 3629 | Rev 3634 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3629 Rev 3633
Line 286... Line 286...
286
 
286
 
287
void *fat_create_node(dev_handle_t dev_handle, int flags)
287
void *fat_create_node(dev_handle_t dev_handle, int flags)
288
{
288
{
289
    fat_idx_t *idxp;
289
    fat_idx_t *idxp;
290
    fat_node_t *nodep;
290
    fat_node_t *nodep;
-
 
291
    fat_bs_t *bs;
-
 
292
    fat_cluster_t mcl, lcl;
-
 
293
    uint16_t bps;
-
 
294
    int rc;
-
 
295
 
-
 
296
    bs = block_bb_get(dev_handle);
-
 
297
    bps = uint16_t_le2host(bs->bps);
-
 
298
    if (flags & L_DIRECTORY) {
-
 
299
        /* allocate a cluster */
-
 
300
        rc = fat_alloc_clusters(bs, dev_handle, 1, &mcl, &lcl);
-
 
301
        if (rc != EOK)
-
 
302
            return NULL;
-
 
303
    }
291
 
304
 
292
    nodep = fat_node_get_new();
305
    nodep = fat_node_get_new();
293
    if (!nodep)
306
    if (!nodep) {
-
 
307
        fat_free_clusters(bs, dev_handle, mcl);
294
        return NULL;
308
        return NULL;
-
 
309
    }
295
    idxp = fat_idx_get_new(dev_handle);
310
    idxp = fat_idx_get_new(dev_handle);
296
    if (!idxp) {
311
    if (!idxp) {
-
 
312
        fat_free_clusters(bs, dev_handle, mcl);
297
        fat_node_put(nodep);
313
        fat_node_put(nodep);
298
        return NULL;
314
        return NULL;
299
    }
315
    }
300
    /* idxp->lock held */
316
    /* idxp->lock held */
301
    if (flags & L_DIRECTORY) {
317
    if (flags & L_DIRECTORY) {
-
 
318
        int i;
-
 
319
        block_t *b;
-
 
320
 
-
 
321
        /*
-
 
322
         * Populate the new cluster with unused dentries.
-
 
323
         * We don't create the '.' and '..' entries, since they are
-
 
324
         * optional and HelenOS VFS does not need them.
-
 
325
         */
-
 
326
        for (i = 0; i < bs->spc; i++) {
-
 
327
            b = _fat_block_get(bs, dev_handle, mcl, i,
-
 
328
                BLOCK_FLAGS_NOREAD);
-
 
329
            /* mark all dentries as never-used */
-
 
330
            memset(b->data, 0, bps);
-
 
331
            b->dirty = false;
-
 
332
            block_put(b);
-
 
333
        }
302
        nodep->type = FAT_DIRECTORY;
334
        nodep->type = FAT_DIRECTORY;
-
 
335
        nodep->firstc = mcl;
-
 
336
        nodep->size = bps * bs->spc;
303
    } else {
337
    } else {
304
        nodep->type = FAT_FILE;
338
        nodep->type = FAT_FILE;
-
 
339
        nodep->firstc = FAT_CLST_RES0;
-
 
340
        nodep->size = 0;
305
    }
341
    }
306
    nodep->size = 0;
-
 
307
    nodep->firstc = FAT_CLST_RES0;
-
 
308
    nodep->lnkcnt = 0;  /* not linked anywhere */
342
    nodep->lnkcnt = 0;  /* not linked anywhere */
309
    nodep->refcnt = 1;
343
    nodep->refcnt = 1;
-
 
344
    nodep->dirty = true;
310
 
345
 
311
    nodep->idx = idxp;
346
    nodep->idx = idxp;
312
    idxp->nodep = nodep;
347
    idxp->nodep = nodep;
313
 
348
 
314
    futex_up(&idxp->lock);
349
    futex_up(&idxp->lock);